All Projects → tigercosmos → node-color-log

tigercosmos / node-color-log

Licence: MIT license
⌨️ The more powerful JavaScript logger for NodeJS and browsers ✏️

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to node-color-log

sprout
Golang logging library supporting log retrieval.
Stars: ✭ 85 (+46.55%)
Mutual labels:  color, logger
logt
🖥️ A colourful logger for the browser
Stars: ✭ 35 (-39.66%)
Mutual labels:  color, logger
chalk
🖍️🎨Composable and simple terminal highlighting package for OCaml.
Stars: ✭ 29 (-50%)
Mutual labels:  color
stellarized
✦ paint vim with the stars ✦
Stars: ✭ 70 (+20.69%)
Mutual labels:  color
przm
🎨 A simple, yet feature rich color picker and manipulator
Stars: ✭ 19 (-67.24%)
Mutual labels:  color
colored json
Generating colored JSON in Rust
Stars: ✭ 17 (-70.69%)
Mutual labels:  color
react-native-log-level
Multi level logger for React Native
Stars: ✭ 13 (-77.59%)
Mutual labels:  logger
croma-react
Save your colors
Stars: ✭ 23 (-60.34%)
Mutual labels:  color
Colorwaver
🎨 An app to detect color palettes in the real world - powered by VisionCamera
Stars: ✭ 365 (+529.31%)
Mutual labels:  color
JINS-MEME-Python-WebSocketServer-Sample
JINS MEME(2021年モデル)のJINS MEME LoggerをPythonのWebSocketサーバーで受信するサンプル
Stars: ✭ 19 (-67.24%)
Mutual labels:  logger
debug.js
Debugger of JavaScript, by JavaScript, for JavaScript
Stars: ✭ 19 (-67.24%)
Mutual labels:  logger
pino-caller
🌲 Include call site of pino log messages
Stars: ✭ 35 (-39.66%)
Mutual labels:  logger
colorzero
Another color manipulation library for Python (originally from picamera)
Stars: ✭ 24 (-58.62%)
Mutual labels:  color
graphql-rails logger
Display GraphQL queries in a more readable format
Stars: ✭ 102 (+75.86%)
Mutual labels:  logger
monolog-sentry-handler
Monolog handler for Sentry PHP SDK v2 with breadcrumbs support
Stars: ✭ 34 (-41.38%)
Mutual labels:  logger
emojione-color
OpenType-SVG font of EmojiOne 2.3
Stars: ✭ 112 (+93.1%)
Mutual labels:  color
color-console
A lightweight header-only C++ library to bring colors to your Windows console with a very-easy-to-use API.
Stars: ✭ 97 (+67.24%)
Mutual labels:  color
nestjs-toolbox
The repository contains a suite of components and modules for Nest.js
Stars: ✭ 166 (+186.21%)
Mutual labels:  logger
global-keypress
Global key press event emitter.
Stars: ✭ 25 (-56.9%)
Mutual labels:  logger
terminal-style
🎨 Return your terminal message in style! Change the text style, text color and text background color from the terminal, console or shell interface with ANSI color codes. Support for Laravel and Composer.
Stars: ✭ 16 (-72.41%)
Mutual labels:  color

Banner

Build Status npm version npm downloads

Node Color Log

The more powerful JavaScript logger for NodeJS and browsers.

node-color-log is a logger package for NodeJS and browsers. It provides more functions than the origin console.log. You can log text with colorful font and colorful background. Also, it has 4 levels log, including debug, info, warnand error. Give you much better experience while developing JavaScript projects.

Demo

Demo

Demo

Demo

Usage

Install

Install package in your project:

npm install node-color-log@latest --save

Import

Put the following code in your js in which you want to log.

const logger = require('node-color-log');

Logger level can be set like this. Logs belongs to this level and above that level will be printed.

logger.setLevel("error"); // it can be any log level.

API

log()

log with attributes, the order of setters can change.

NOTE: log() need to put behind of attribute setter(at the end).

joint() can connect different style of message in a line.

color() and bgColor() includes: black, red, green, yellow, blue, magenta, cyan, white.

Usage:

// normal log
logger.log(message)
// Attribute log
logger.color('red').bgColor('blue')
      .bold().italic().dim().reverse().underscore().strikethrough()
      .log(message);
// Joint log
logger.color('red').bold().log(message_style_1).joint()
      .bgColor('white').italic().log(message_style_2).joint()
      .strikethrough().log(message_style_3);

// log multiple arguments
logger.log(obj1, arr2, str3);

fontColorLog(), bgColorLog(), colorLog()

  • message here must be a string.

  • Color includes: black, red, green, yellow, blue, magenta, cyan, white.

  • setting is optional. Keys in setting need to be boolean, and all are false by default.

Parameters:

const color = 'red';
const message = 'any string you will put into console.log';
const setting = {
    bold: true,
    dim: true,
    underscore: true,
    reverse: true,
    italic: true,
    strikethrough: true
}

Usage:

// only set font color
logger.fontColorLog('red', message, setting);
// only set background color
logger.bgColorLog('yellow', message, setting);
// set font and background color
logger.colorLog({
    font: 'black',
    bg: 'yellow'
}, message, setting);

success(), debug(), info(), warn(), error()

With prefix that has background color

Usage:

// Success level, with prefix "[SUCCESS]"
logger.success(message);
// debug level, with prefix "[DEBUG]"
logger.debug(message);
// Info level, with prefix "[INFO]"
logger.info(message);
// Warn level, with prefix "[WARN]"
logger.warn(message);
// Error level, with prefix "[ERROR]"
logger.error(message);


// Level logs enable multiple arguments
logger.debug(obj1, arr2, str3);

The output looks like:

2018-08-14T18:23:09.836Z [SUCCESS] This is success mode
2018-08-14T18:23:09.837Z [DEBUG] This is debug mode
2018-08-14T18:23:09.838Z [INFO] This is info mode
2018-08-14T18:23:09.838Z [WARN] This is warn mode
2018-08-14T18:23:09.839Z [ERROR] This is error mode

setLevel() & LOGGER environment variable

If you want to set mask for levels, simply add the line at the front. Levels below the setting level will all be hidden. There are four levels, which are success, debug, info, warn, error, or disable in lower-case.

logger.setLevel("info"); // success < debug < info < warn < error < disable
logger.debug("This `debug` will be hidden");
logger.error("This `error` will be shown");

logger.setLevel("disable"); // hide every logs

Or, you can set the environment variable LOGGER, such as LOGGER=info npm start, where it's equal to setLevel("info").

setLevelNoColor(), setLevelColor()

Level logs print in colors as a default.

You can set setLevelNoColor() to turn off the setting, and use setLevelColor() to reverse it.

None color mode is helpful for text files or browser environments.

logger.setLevelNoColor();

setDate()

The default time format is toISOString, but you can change it by using setDate(callback)

logger.setDate(() => (new Date()).toLocaleTimeString())
logger.info("This is an info message") // 5:17:59 pm [INFO] This is an info message

Log Files

If you want to save the logs to files, you can use shell pipes:

For example, it saves logs belonged and above warn to log.txt:

$ LOGGER=warn node index.js > log.txt

To see more example, you can check ./test.js or run npm test to see the result.

Contribute

Any issues and PRs are very welcome!

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].