
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
logging.js
Advanced tools
Stream based logging module for nodejs/iojs.
npm install logging.js
var logging = require('logging.js'),
log = logging.get('mylogger');
log.addRule({name: 'stdout', stream: process.stdout});
log.info('logging from %(from)s to %(to)s', {from: 'mylogger', to: 'stdout'})
// => 2015-04-25 14-28-58,548 info mylogger[8274]: logging from mylogger to stdout
There are 5 levels available as:
logging.DEBUG
logging.INFO
logging.WARN // alias `logging.WARNING`
logging.ERROR
logging.CRITICAL
In a single node process, logging.get('mylogger') will always return the same logger object,
because all loggers are registered in a global registry after they are created.
logging.get('name') === logging.get('name'); // true
When we create a new logger by name, if there is
a fatherLogger which enables propagate and its name is a long
enough prefix of name, the new logger will propagate rules
from fatherLogger:
var fatherLogger = logging.get('app');
var childLogger = logging.get('app.module');
Get a logger from global registry, if the logger dose not exist, create one and return it.
var log = logging.get('mylogger');
A logging rule is an object like:
{
name: 'stdout', // a rule has a name, required
stream: process.stdout, // a writable stream, required
level: logging.INFO, // logging level, default: logging.INFO
formatter: '...', // formatter, string or function (optional)
levelCmp: logging.LEVEL_GE // do logging only if current message level greater than rule's level
}
If no rules were added when logging, process.stderr will be used.
Remove a rule from logger by name.
Get a rule from logger by name.
Enable/Disable this logger to be a fatherin the future (the Logger constructor sets
log.propagate = true).
log.debug(fmt, ...)
log.info(fmt, ...)
log.warn(fmt, ...) // alias log.warning(fmt, ...)
log.error(fmt, ...)
log.critical(fmt, ...)
A formatter can be a string or a function like function(record) {..}.
For string case, an example:
'%(asctime)s %(levelname)s %(name)s[%(pid)s]: %(message)s'
And all available named attributes for a log record:
name logger name
level record level (number)
levelName record level (string)
levelname record level (string, lowercase)
fmt record formatter string
args record arguments
message record message (fmt % args)
pid process id
created the datetime when this record created
asctime human readable time string, e.g. '2003-07-08 16:49:45,896'
For function case, it should like function(record) {return string}
Logging enables 2 handy string formatting types:
log.info('%s %d', 'val', 1) // 'val 1'
log.info('%(key1)s %(key2)d', {key1: 'abc', key2: 123}) // 'abc 123'
We can add multiple rules (or say streams) to a logger, here is an example for file stream:
var fs = require('fs');
var log = logging.get('myapp');
log.addRule({name: 'file', stream:
fs.createWriteStream('myapp.log', {flags: 'a'})});
log.info('logging from the maginc world');
For example, we want to log messages to 3 files by level: error.log, warning.log and all.log:
var fs = require('fs');
var log = logging.get('myapp');
log.addRule({name: 'all',
stream: fs.createWriteStream('all.log', {flags: 'a'})});
log.addRule({name: 'error', level: logging.ERROR, levelCmp: logging.LEVEL_EQ,
stream: fs.createWriteStream('error.log', {flags: 'a'})});
log.addRule({name: 'warning', level: logging.WARNING, levelCmp: logging.LEVEL_EQ,
stream: fs.createWriteStream('warning.log', {flags: 'a'})});
MIT. (c) Chao Wang hit9@icloud.com
FAQs
Stream based logging module for nodejs/iojs.
We found that logging.js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.