A better logger for nodejs
Sometimes the console can't point the right error stack,so the vlog will replace it. vlog will show the error stack in fine format, add your custom msg, and replace console.
V0.2.4
- ee and eo can save unlimit arguments as JSON objects in log
- Plugin supported, now you can do anything (save error to other file, sent to logstash...) with plugin, try this:
var plugA = { console; consolelog; } { console; consoleerror; };var vlog = ;vlog;
Installation
npm install vlog --save
Usage
//reqire vlog with __filenamevar vlog = ; var { if !callback return; var newErr = 'err1'; /** * vlog.ee * replace **error** in callback * 返回一个error堆栈,附加当前错误,用于callback到上层 * @param * @param * @param {object,object...} other objects,will be JSON.stringify and save to log * @return */ //callback an error ; //or use null, vlog will create a Error obj for you //callback(vlog.ee(null,'error msg1','other object to log'));}; var { if e /** * vlog.eo * print the error stack in console * 打印错误堆栈 * @param * @param * @return */ vlog; }; ;
will got this:
--------- ERR: 2015-11-21 16:39:32 ---------testErrA: testvlogjstest2 error; testvlogjserror msg1 @P:--"other object to log"; at Objectme at at Object<anonymous> /xxx/test/testvlogjs:24:7 at Module at ObjectModule_extensions at Module at FunctionModule at FunctionModule at at nodejs:972:3
replace the console functions,so you can add more function with plugin:
vlog; // = console.logvlog; // = console.errorvlog; // = console.warnvlog; // = console.infovlogdirusernameuserage; // = console.dir