Gathering detailed insights and metrics for node-color-log
Gathering detailed insights and metrics for node-color-log
Gathering detailed insights and metrics for node-color-log
Gathering detailed insights and metrics for node-color-log
npm install node-color-log
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
70 Stars
108 Commits
20 Forks
4 Watching
1 Branches
12 Contributors
Updated on 16 Nov 2024
JavaScript (99.46%)
PowerShell (0.27%)
Shell (0.27%)
Cumulative downloads
Total Downloads
Last day
-15%
6,392
Compared to previous day
Last week
-26.4%
44,945
Compared to previous week
Last month
27.1%
251,193
Compared to previous month
Last year
341.2%
2,003,896
Compared to previous year
2
A lightweight and more 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 fonts and colorful backgrounds. Also, it has 4 levels log, including debug
, info
, warn
and error
. Give you a much better experience while developing JavaScript projects.
Winston and Pino are famous loggers for JaveScript, but they are too heavy and fancy. Sometimes we just want to have a simple logger, and don't want to spend time learning a fancy library. Then, node-color-log
is your best choice.
Install package in your project:
1npm install node-color-log@latest --save
Put the following code in your js
in which you want to log.
1const logger = require('node-color-log');
Logger level can be set like this. Logs belongs to this level and above that level will be printed.
1logger.setLevel("error"); // it can be any log level.
log()
log with attributes, the order of setters can change.
NOTE: log()
need to put behind of attribute setter(at the end).
append()
can appends the contents in one line. (Note: old joint
is now deprecated.)
color()
and bgColor()
includes: black
, red
, green
, yellow
, blue
, magenta
, cyan
, white
.
reset()
can clear the previous attributes in the same line.
Usage:
1// normal log 2logger.log(message) 3// Attribute log 4logger.color('red').bgColor('blue') 5 .bold().italic().dim().reverse().underscore().strikethrough() 6 .log(message); 7// use `append`` to joint contents, and use `log` to print out at the end 8logger.color('red').bold().append('message_style_1') 9 .bgColor('white').italic().append('message_style_2') 10 .strikethrough().log('message_style_3'); 11 12// use `reset` to clean the attributes 13logger.bgColor('red').append('background red color message') 14 .reset() // by calling this, background is reset 15 .log('default background color message'); 16 17// log multiple arguments 18logger.log(obj1, arr2, str3);
setLogStream
You can redirect the logs to the stream.
for example, you can write the log into the file:
1fileStream = fs.createWriteStream('test.log'), 2logger.setLogStream(fileStream) 3 4logger.log("hi"); 5logger.error("hello", "world"); 6 7fileStream.close()
you can use less -R test.log
to see the result.
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:
1const color = 'red'; 2const message = 'any string you will put into console.log'; 3const setting = { 4 bold: true, 5 dim: true, 6 underscore: true, 7 reverse: true, 8 italic: true, 9 strikethrough: true 10}
Usage:
1// only set font color 2logger.fontColorLog('red', message, setting); 3// only set background color 4logger.bgColorLog('yellow', message, setting); 5// set font and background color 6logger.colorLog({ 7 font: 'black', 8 bg: 'yellow' 9}, message, setting);
success()
, debug()
, info()
, warn()
, error()
With prefix that has background color
Usage:
1// Success level, with prefix "[SUCCESS]" 2logger.success(message); 3// debug level, with prefix "[DEBUG]" 4logger.debug(message); 5// Info level, with prefix "[INFO]" 6logger.info(message); 7// Warn level, with prefix "[WARN]" 8logger.warn(message); 9// Error level, with prefix "[ERROR]" 10logger.error(message); 11 12 13// Level logs enable multiple arguments 14logger.debug(obj1, arr2, str3);
The output looks like:
12018-08-14T18:23:09.836Z [SUCCESS] This is success mode 22018-08-14T18:23:09.837Z [DEBUG] This is debug mode 32018-08-14T18:23:09.838Z [INFO] This is info mode 42018-08-14T18:23:09.838Z [WARN] This is warn mode 52018-08-14T18:23:09.839Z [ERROR] This is error mode
setLevel()
& LOGGER
environment variableIf 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.
1logger.setLevel("info"); // success < debug < info < warn < error < disable 2logger.debug("This `debug` will be hidden"); 3logger.error("This `error` will be shown"); 4 5logger.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.
1logger.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
createNamedLogger()
You can create a named logger by calling createNamedLogger()
logger1 = logger.createNamedLogger("Test 1");
logger2 = logger.createNamedLogger("Test 2");
logger1.info('something happened'); // 2022-08-20T04:56:17.834Z [Test 1] [INFO] something happened
logger2.info('something happened'); // 2022-08-20T04:56:17.835Z [Test 2] [INFO] something happened
Any issues and PRs are very welcome!
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
3 existing vulnerabilities detected
Details
Reason
Found 8/30 approved changesets -- score normalized to 2
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More