Gathering detailed insights and metrics for @lskjs/colors
Gathering detailed insights and metrics for @lskjs/colors
npm install @lskjs/colors
Typescript
Module System
Node Version
NPM Version
68.6
Supply Chain
97
Quality
83.1
Maintenance
100
Vulnerability
100
License
v2.2.0-beta.20
Updated on Feb 03, 2021
v2.2.0-beta.19
Updated on Feb 02, 2021
v2.2.0-beta.17
Updated on Feb 01, 2021
v2.2.0-beta.16
Updated on Feb 01, 2021
v2.2.0-beta.15
Updated on Feb 01, 2021
v2.2.0-beta.14
Updated on Feb 01, 2021
JavaScript (66.57%)
HTML (22.31%)
TypeScript (8.41%)
CSS (2.66%)
Shell (0.04%)
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Total Downloads
19,478
Last Day
29
Last Week
189
Last Month
867
Last Year
11,060
MIT License
38 Stars
3,457 Commits
19 Forks
9 Watchers
72 Branches
14 Contributors
Updated on May 30, 2024
Minified
Minified + Gzipped
Latest Version
3.18.0
Package Id
@lskjs/colors@3.18.0
Unpacked Size
86.34 kB
Size
16.12 kB
File Count
38
NPM Version
lerna/7.1.4/node@v20.5.1+x64 (linux)
Node Version
20.5.1
Published on
Nov 06, 2023
Cumulative downloads
Total Downloads
Last Day
0%
29
Compared to previous day
Last Week
-10%
189
Compared to previous week
Last Month
-10.3%
867
Compared to previous month
Last Year
62.4%
11,060
Compared to previous year
1
@lskjs/log – Логгер совмещающий лучшие черты morgan, winston, bunyan, logrus. debug. Базируется на debug-level.
1# yarn 2yarn i @lskjs/log 3 4# npm 5npm i @lskjs/log
$ npm install --save @lskjs/log
@lskjs/log
provides 6 log levels which are trace
, debug
, info
, warn
, error
,
fatal
, and off
.
Each level has a corresponding method debug
-> log.debug
... fatal
-->
log.fatal
which shall be used to indicated the level to log.
The characters %s
, %d
, %i
, %f
, %j
, %o
, %O
, %%
are supported formatters when
given in the first argument.
1const Log = require('@lskjs/log') 2// creates a logger for <namespace> `test` 3const log = new Log('test') 4 5// or using a global Log instance 6const log = require('@lskjs/log').log('test') 7 8log.fatal(new Error('fatal')) // logs an Error at level FATAL 9log.error(new Error('boom')) // logs an Error at level ERROR 10log.warn('huh %o', {ghost: 'rider'}) // logs a formatted object at level WARN 11log.info('%s world', 'hello') // logs a formatted string at level INFO 12log.debug({object: 1}) // logs an object at level DEBUG 13log.log('always logs') // always logs regardless of set level
Running levels.js
without environment variables will show no output (apart from log.log
).
Setting only DEBUG_LEVEL
shows all lines with their respective level.
Combined with DEBUG
, using comma separated namespaces, only
those log lines with matching namespace and level get logged.
The following table gives an overview of possible combinations:
DEBUG_LEVEL | DEBUG | Output |
---|---|---|
-- | -- | no output |
fatal | -- | logs only log.fatal |
error | -- | log.fatal, log.error |
warn | -- | log.fatal, log.error, log.warn |
info | -- | log.fatal, log.error, log.warn and log.info |
debug | -- | log.fatal, log.error, log.warn, log.info and log.debug |
trace | -- | log.fatal, log.error, log.warn, log.info, log.debug and log.trace |
-- | <namespaces> | log.fatal, to log.debug which apply to <namespaces> . Same behavior as debug. |
fatal | <namespaces> | log.fatal for all <namespaces> only |
error | <namespaces> | log.fatal, log.error for <namespaces> only |
warn | <namespaces> | log.fatal, to log.warn for <namespaces> only |
info | <namespaces> | log.fatal, to log.info for <namespaces> only |
debug | <namespaces> | log.fatal, to log.debug for <namespaces> only |
trace | <namespaces> | log.fatal, to log.trace for <namespaces> only |
-- | error:n1,debug:n2,fatal:* | Logs namespace n1 at level error , namespace n2 at level debug and all other namespaces (* ) at level fatal |
datal | error:n1,n2 | Logs n1 at level error , n2 at level fatal . All other namespaces will NOT get logged |
Run the server.js example with different settings:
No output
1$ node examples/server.js
Logging .info and .error
1$ DEBUG_LEVEL=info node examples/server.js
Logging .error for server only
1$ DEBUG_LEVEL=error DEBUG=server node examples/server.js
Logging .error in production mode (JSON without colors)
1$ NODE_ENV=production DEBUG_LEVEL=error node examples/server.js
Behavior is as with debug.
1$ DEBUG=server,client:A node examples/server.js
Log server
at level info
, and all other modules at level error
1$ DEBUG=info:server,error:* node examples/server.js
Common
Setting | Values | Description
---- | ---- | ----
DEBUG |
Node only
Setting | Values | NODE_ENV=
development
| Description
---- | ---- | ---- | ----
DEBUG_JSON | true/false | false | use JSON format instead of string based log
DEBUG_SERVERINFO | true/false | false | adds server information like pid
and hostname
DEBUG_HIDE_DATE | true/false | false | hides date from log output default false
For NODE_ENV !== 'development'
the default logging is in JSON format using serverinfo and date.
Browsers only
Setting | Values | Description
---- | ---- | ----
DEBUG_URL | URL | log in JSON format to server (needs middleware.js
at the server side)
In the browser localStorage
is used to set/save the settings.
E.g. to enable level ERROR an all namespaces type in console and refresh your page/ app:
localStorage.DEBUG_LEVEL='error'
localStorage.DEBUG='*'
You may set the global log options with:
1const fs = require('fs') 2const Log = require('@lskjs/log') 3 4// log into file instead of process.stderr 5const stream = fs.createWriteStream('./my.log') 6 7// The options will be set for all Loggers... 8Log.options({ 9 level: 'DEBUG', 10 json: true, 11 serverinfo: true, 12 hideDate: false, 13 colors: false, 14 stream 15}) 16const log = new Log('*') 17 18log.debug({object: 1}) // ...
Option name | Setting | env | Type | Description
----- | ---- | ---- | ---- | ----
level | DEBUG_LEVEL | both | String |
namespaces | DEBUG | both | String |
json | DEBUG_JSON | node | Boolean |
spaces | DEBUG_SPACES | node | Number | JSON spaces
hideDate | DEBUG_HIDE_DATE | both | Boolean |
colors | DEBUG_COLORS | both | Boolean |
stream | -- | node | Stream | output stream (defaults to process.stderr
)
url | DEBUG_URL | browser | String |
formatters | -- | both | Object | custom formatters
(From bunyan)
fatal
: The service/app is going to stop or becomes unusable.
An operator should definitely look into this soon.error
: Fatal for a particular request, but the service/app continues servicing.
An operator should look at this soon(ish)warn
: A note on something that should probably be looked at by an operator eventually.info
: Detail on regular operation.debug
: Anything else, i.e. too verbose to be included in INFO
level.trace
: Anything else, i.e. too verbose to be included in INFO
level.Namespaces select dedicated packages for logging (check Conventions)
considering the level selected with DEBUG_LEVEL
. To choose a different log-level
prefix the namespace with the level to be set for that namespace.
E.g. to log all packages on level FATAL
, test
on ERROR
, log:A
on WARN
. As a side-effect *
will also cause all modules using debug being logged.
$ DEBUG_LEVEL=fatal DEBUG=ERROR:test,WARN:log:A,* node examples/levels.js
ERROR test Error: boom
FATAL test fatal test +7ms
WARN log:A huh {"ghost":"rider"} +0ms
ERROR log:A Error: baam
FATAL log:A fatal A +1ms
FATAL log:B fatal B +0ms
using-debug using debug +0ms
using-debug:A using debug - feature A +1ms
So maybe consider using DEBUG=...,FATAL:*
instead:
$ DEBUG=error:test,warn:log:A,fatal:*,using-debug:* node examples/levels.js
ERROR test Error: boom
FATAL test fatal test +7ms
WARN log:A huh {"ghost":"rider"} +0ms
ERROR log:A Error: baam
FATAL log:A fatal A +1ms
FATAL log:B fatal B +0ms
using-debug:A using debug - feature A +1ms
(from debug)
If you're using this in one or more of your libraries, you should use the name of
your library so that developers may toggle debugging as desired without guessing
names. If you have more than one debuggers you should prefix them with your
package name and use ":" to separate features. For example bodyParser
from
Connect would then be connect:bodyParser
. If you append a *
to the end of
your name, it will always be enabled regardless of the setting of the DEBUG
environment variable. You can then use it for normal output as well as debug output.
(from debug)
The *
character may be used as a wildcard. Suppose for example your library
has debuggers named connect:bodyParser
, connect:compress
, connect:session
,
instead of listing all three with DEBUG=connect:bodyParser,connect:compress,connect:session
,
you may simply do DEBUG=connect:*
, or to run everything using this module
simply use DEBUG=*
.
You can also exclude specific debuggers by prefixing them with a -
character.
For example, DEBUG=*,-connect:*
would include all debuggers except those starting with connect:
.
@lskjs/log
supports two types of outputs
NODE_ENV=development
. Can be forced using DEBUG_JSON=0
DEBUG_JSON=1
When using %j
, %o
, %O
all will expand to %j
JSON, so there is no difference when using in node.
Nonetheless it is not recommended to use these formatters for logging errors and objects as this complicates later log inspection.
Each log records into a single JSON stringified line.
Core fields are:
level
: One of the five log levels.name
: The name of the namespace logged.msg
: A message which should give reason for logging the line.hostname
: Hostname of the server. (Requires option serverinfo)pid
: PID of the logged process. (Requires option serverinfo).time
: Timestamp (Suppress with option hideDate).diff
: Difftime in milliseconds.When logging a message string, number or a formatted string it will show up under msg
like:
1log.debug('a %s, a number %d, an %o and %j', 'string', 1.2, {object: 1}, {NOT: 'RECOMMENDED'}) 2// > 3{ "level": "DEBUG", // log level 4 "name": "package:feature", // the namespace of the logger 5 "msg": "a string, a number 1.2, an {\"object\":1} and {\"NOT\":\"RECOMMENDED\"}", // the formatted message 6 "hostname": "server", // server hostname 7 "pid": 8310, // process pid 8 "time": "2017-11-08T21:01:00.025Z", // timestamp as ISOString 9 "diff": 5 // difftime in ms 10}
Objects without formatters get assigned, arrays will show up under arr
:
1log.info({object: 1}, {json: true}, [1, 2, 3], '%s #%d', 'message', 1) 2// > 3{ "level": "INFO", 4 "name": "package:feature", 5 "msg": "message #1" 6 "object": 1, 7 "json": true, 8 "arr": [1,2,3], 9 "time": "2017-11-09T21:09:49.482Z", 10 "diff": 0 11}
An error gets logged under err
1const err = new TypeError('bam') 2err.status = 500 3log.error(err, {object: 1}) // you may add an additional object 4// > 5{ "level":"ERROR", 6 "name":"package:feature", 7 "msg":"bam", 8 "err": { // the error object 9 "name":"TypeError", 10 "stack":"Error: bam\n at Object.<anonymous> (...\n at bootstrap_node.js:608:3", 11 "status": 500 12 }, 13 "object": 1, 14 "time":"2017-11-09T21:16:16.764Z", 15 "diff":0 16}
You may use custom formatters e.g. to display numbers converted into hex-format.
1const Log = require('..') 2Log.options({level: 'debug'}) 3const log = new Log('test', {formatters: { 4 h: (n) => `x${n.toString(16).toUpperCase()}` 5}}) 6 7log.debug('%h', 255) // logs 255 as hex 'xFF'
If logging an object you may define a toJSON()
function on that object to change proper logging of the object itself:
1const Log = require('@lskjs/log') 2const log = new Log('*') 3 4function reqToJSON () { 5 const {ip, method, url} = this 6 return {ip, method, url} 7} 8 9// assume a request obj 10const req = { 11 method: 'GET', url: '/path', ip: '10.10.10.10', 12 headers: {'user-agent': 'Custom/2.0'}, connection: {/* ... */} 13} 14req.toJSON = reqToJSON.bind(req) 15 16log.debug({req: req}) 17//> DEBUG * {"req":{"ip":"10.10.10.10","method":"GET","url":"/path"}} +0ms
To log debug messages from the browser on your server you can enable a logger middleware in your express/ connect server.
1const app = require('express')() 2const {logger} = require('@lskjs/log') 3 4app.use('./@lskjs/log', logger({maxSize: 100})) 5...
In your single page application use:
1import Log from '@lskjs/log' 2 3localStorage.setItem('DEBUG_URL', '/api/log') 4localStorage.setItem('DEBUG', 'myApp*') 5// ... 6const log = new Log('myApp') 7 8log.debug('my first %s', 'logline')
Check example at examples/app
. To run it use:
1DEBUG=* node examples/app/server.js
and open http://localhost:3000
This project is licensed under the MIT License - see the LICENSE file for details
Igor Suvorov 💻 🎨 🤔 |
git checkout -b features/fooBar
)git commit -am 'feat(image): Add some fooBar'
)git push origin feature/fooBar
)No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
no binaries found in the repo
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
no SAST tool detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
145 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-03-03
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