node-custom-console

0.2.4 • Public • Published

node-custom-console

NPM version Build Status Coverage Status dependency Status devDependency Status

Custom console for Node.js log.

Usage

Just replace your console with this module.

var console = require('node-custom-console')('module1');
console.log('foo', 'bar')
// > 2014-10-02T06:15:16.830Z [log] 44999 module1: foo bar
 
var console = require('node-custom-console')('module2');
console.info('foo', 'bar')
// > 2014-10-02T06:15:16.830Z [info] 44999 module2: foo bar

Debug Target

You can specify the debug targets.

process.env.NODE_DEBUG='module1'
 
var console = require('node-custom-console')('module1');
console.log('foo', 'bar')
// > 2014-10-02T06:15:16.830Z [info] 44999 module1: foo bar
 
var console = require('node-custom-console')('module2');
console.info('foo', 'bar')
// No output

You can also set multiple targets with module1,module2 and all with *.

Debug Level

You can specify the debug levels.

process.env.NODE_DEBUG='module1:info'
 
var console = require('node-custom-console')('module1');
console.log('foo', 'bar')
// No output
 
console.info('foo', 'bar')
// > 2014-10-02T06:15:16.830Z [info] 44999 module1: foo bar

Here is the priority order of available levels. log < info < warn < error

Custom Formatter

Furthermore, you can use custom formatter as below.

var console = require('node-custom-console')('module1', formatter: function() {
  var args = [];
  args.push(this.tag + '-' + this.severity);
  args = args.concat([].slice.call(arguments, 0));
  args.push(';');
  return args;
});
console.info('foo', 'bar')
// > chai-info foo bar ;

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Copyright

Copyright (c) 2014 Daisuke Taniwaki. See LICENSE for details.

Readme

Keywords

Package Sidebar

Install

npm i node-custom-console

Weekly Downloads

0

Version

0.2.4

License

MIT

Last publish

Collaborators

  • dtaniwaki