Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
devnull is an feature rich logging library for Node.js. It was designed from
the ground up to assist you during development and be powerful in production. It
works just like the regular console.log
statements you have in code, it uses
the same formatter for logging to the terminal and has the same API. It's
basically a cherry on the top :).
The module automatically adds intelligent namespaces to all your log calls so you can easily track back those log statements in your code without having to remember where you placed them.
The logger is build on top of the EventEmitter prototype. This allows you to handle all critical log messages in one central location. You might want to be notified when you application starts emitting critical errors. I know I would.
It supports different logging transports. You might want to log to the terminal in production but to MongoDB in production so you have a centralized location of all your logs. Each logger can have multiple transports.
The image above is the result of the example/logging.js
The module is tested against Node.js 0.4 and 0.6 and can be installed using the Node.js Package Manager, also known as NPM.
npm install devnull
If you don't have NPM installed on your system you can get it at http://npmjs.org
You can either initialize the default logger:
var Logger = require('devnull')
, logger = new Logger();
logger.log('hello world');
logger.info('pew pew');
logger.error('oh noes, something goes terribly wrong');
Or configure a customized instance using the options argument:
var Logger = require('devnull')
, logger = new Logger({ timestamp: false });
logger.log('hello world');
...
The following options are available for configuring your customized instance:
Configure the module for different environments, it follows the same API as Express.js.
env (string) environment fn (function) callback
var Logger = require('devnull')
, logger = new Logger();
// runs always
logger.configure(function () {
logger.log('running on the things');
});
// only runs in production
logger.configure('production', function () {
logger.log('running in production');
});
logger.configure('development', function () {
logger.log('running in development');
});
Adds another transport to the logger. We currently ship 2 different transports inside the module (stream and mongodb).
These transports can be required using
require('devnull/transports/<transportname>')
.
Transport (Transport) a uninitialized transport instance. options (object) options for the transport.
var Logger = require('devnull')
, logger = new Logger();
// use the stream transport to log to a node.js stream
logger.use(require('devnull/transports/stream'), {
stream: require('fs').createWriteStream('logger.log');
});
// also exports all transports :)
var transport = require('devnull/transports');
// and add mongodb to production logging
logger.configure('production', function () {
logger.use(transport.mongodb, {
url: 'mongodb://test:test@localhost:27017/myapp'
});
});
logger.warning('hello world');
Removes all transports of that instance.
Transport (Transport) a transport
var Logger = require('devnull')
, logger = new Logger({ base: false })
, transports = require('devnull/transports');
logger.use(transports.stream);
logger.remove(transports.stream);
Because the Logger is build upon the EventEmitter you can also start listening
for log messages. This is set to warning levels by default in the configuration
options. In addition to listening to the log message you can also listen to the
events of the transports. These are prefixed with transport:
. The following
events are emitted:
And the transport events:
transport:failed(err)
transport failed to initializetransport:error(err, log)
transport failed to write the log due to an errortransport:write(log)
transport written the log messageevent (string) event to listen for fn (function) callback, receives args (array), stack (stack/callsite)
var Logger = require('devnull')
, logger = new Logger();
logger.on('error', function (args, stack) {
// args = foo bar, 1
// stack = stack trace that we used to generate the namespace
email('errors@pew.pew', 'error!', args);
});
logger.error('foo bar', 1);
Ignore the output of a given file name, so everything that is logged in that file is ignored.
env (string) file
var Logger = require('devnull')
, logger = new Logger();
logger.ignore('my_other_module.js');
Unignore the file that you ignored above
env (string) file
var Logger = require('devnull')
, logger = new Logger();
logger.ignore('my_other_module.js');
logger.unignore('my_other_module.js');
The logger has the following methods available for logging. The () is the log level.
FAQs
A simple logger with automatic function detection.
We found that devnull demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.