Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
cli-logger
Advanced tools
Logger implementation for command line interfaces.
npm install cli-logger
npm test
Example programs are in the bin directory and there are many usage examples in the test suite.
Unless streams have been configured all log messages are written to process.stdout
.
Normal mode uses log levels that correspond to the bunyan log levels and behaviour (log messages are written if they are greater than or equal to the configured log level):
var log = require('cli-logger');
var conf = {level: log.WARN};
logger = log(conf);
logger.warn('mock %s message', 'warn');
// this will not be logged as the log level is warn
logger.info('mock %s message', 'info');
Using bitwise log levels allows fine-grained control of how log messages are routed, to enable bitwise mode pass true
as the second argument when creating the logger:
var log = require('cli-logger');
var conf = {level: log.BW_INFO|log.BW_FATAL};
logger = log(conf, true);
logger.info('mock %s message', 'info');
If you just want to disable one or two log levels it is more convenient to use the XOR
operator:
var log = require('cli-logger');
var conf = {level: log.BW_ALL^log.BW_TRACE};
logger = log(conf, true);
logger.info('mock %s message', 'info');
Note that in normal mode you may use string log levels, such as 'trace'
, but in bitwise mode you may only use integer log levels.
name
: The name of the logger, default is basename(process.argv[1])
.json
: Print log records as newline delimited JSON, default is false
.level
: A default log level to use when a stream does not explicitly specify a log level, default is INFO
.src
: A boolean that indicates that file name, line number and function name (when available) should be included in the log record, default is false
.stack
: A boolean used in conjunction with src
to also include an array of the stack trace caller information, default is false
.console
: A boolean indicating that console methods should be used when writing log records, this enables the ttycolor integration, default is false
.serializers
: Map of log record property names to serialization functions,
default is null
.writers
: Map of log level string names to console functions, default is
null
. Use this to customize the functions used when console
is true
,
see writers.streams
: An array or object that configures the streams that log records are written to, by default if this property is not present a single stream is configured for process.stdout
.If you specify any unknown properties in the configuration then these are considered persistent fields and are added to every log record. This is a convenient way to add labels for sub-components to log records.
Configuring output streams is typically done using an array, but as a convenience an object may be specified to configure a single output stream:
var log = require('cli-logger');
var conf = {streams: {stream: process.stderr, level: log.WARN}}
var logger = log(conf);
// ...
You may configure a file stream by using the path
stream property. For example, to log the INFO
level and above to stdout
and ERROR
and above to a file:
var log = require('cli-logger');
var conf = {streams: [
{
stream: process.stdout,
level: log.INFO
},
{
path: 'log/errors.log',
level: log.ERROR
}
]};
var logger = log(conf);
// ...
When creating file streams the default flags used is a
you may specify the flags
property to change this behaviour:
var log = require('cli-logger');
var conf = {streams: [
{
path: 'log/errors.log',
flags: 'ax',
level: log.ERROR
}
]};
var logger = log(conf);
// ...
The encoding
and mode
options supported by fs.createWriteStream
are also respected if present.
FAQs
Logger implementation for command line interfaces
The npm package cli-logger receives a total of 2,891 weekly downloads. As such, cli-logger popularity was classified as popular.
We found that cli-logger 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.