nodejs-simple-log
Overlay to the function console.log
Install
npm install node-simple-log
API
config()
Set templates and colors simple.config(key, value);
var simple = require('node-simple-log');
simple.config('defaultTemplate', '[{time}] [{parent}]: {arguments}');
simple.config('errorTemplate', '[{time}] [{rel-file}]: {arguments}');
simple.config('myLogTemplate', '{time} {ref-file-line} | {arguments}');
Templates
Posible features:
{time}complete data like2013-04-20 11:00:26{parent}object name{parent.method}object and method{file}file with path{file-line-col}file with path, line and column{file-line}file with path and line number{rel-file-line-col}file with path (withoutprocess.cwd()andprocess.argv[1]), line and column{rel-file-line}file with path (withoutprocess.cwd()andprocess.argv[1]) and line{rel-file}file with path (withoutprocess.cwd()andprocess.argv[1]){arguments}if not set arguments are add on end line
Colors
Posible colors and decorations:
resetunderlineblackredgreenyellowbluemagentacyangraywhitelight-blacklight-redlight-greenlight-yellowlight-bluelight-magentalight-cyanlight-whiteback-blackback-redback-greenback-yellowback-blueback-magentaback-cyanback-whiteback-dark
name()
Set name log to next context when use log
var simple = require('node-simple-log');
// Set config to your own log type
simple.config('myLogTemplate', '{time} {ref-file-line} | {arguments}');
simple.config('myLogColor', 'light-red');
simple.config('myLogArgColor', 'underline');
// set context and print log
simple.name('myLog').log('my custom log');
Standard print methods:
var simple = require('node-simple-log');
simple.log('my log', simple);
simple.info('my info');
simple.warn('my warn');
simple.error('my error');
simple.ok('my green log');
simple.msg('my msg');
You can add your log type to global object:
var simple = require('node-simple-log');
simple.myLog = function() {
this.run('myLog', arguments);
}
Example
var simple = require('node-simple-log');
simple.log('Some', 'log');
function Foo() {
simple.log('Some', 'log', 'in', 'constructor');
}
Foo.prototype.bar = function() {
simple.log('Some', 'log', 'in', 'Foo.bar()');
}
function Bar() {
simple.log('Some', 'log', 'in', 'Bar()');
}
var obj = new Foo();
obj.bar();
Bar();
Result:
[2012-09-30 15:53:44] [-] Some log
[2012-09-30 15:53:44] [new Foo] Some log in constructor
[2012-09-30 15:53:44] [Foo] Some log in Foo.bar()
[2012-09-30 15:53:44] [Bar] Some log in Bar()
See more in example directory
