Browse files

updated to 0.5.1

  • Loading branch information...
1 parent d33420a commit 6ed4997fdaacfb4dae5ec23fdd8a1cadc7f6c012 @baryon committed Jun 27, 2012
Showing with 22 additions and 7 deletions.
  1. +4 −0 README.md
  2. +4 −0 example/format2.js
  3. +13 −6 lib/console.js
  4. +1 −1 package.json
View
4 README.md
@@ -380,6 +380,10 @@ module.exports = function(conf) {
## History
+### 0.5.1
+
+* feature: add args into data object, now we can check args in preprocess, see example format2.js, merge from yasuyk04/work
+
### 0.5.0
* performance: speed up when the format don't include method,path,line,pos,file, thanks sharonjl's issue report
View
4 example/format2.js
@@ -18,6 +18,10 @@ var logger = require('tracer')
}
data.title = data.title.toUpperCase();
+
+ if(data.args[0]=='hello'){
+ data.message += ' node.js';
+ }
}
});
View
19 lib/console.js
@@ -18,7 +18,7 @@ module.exports = (function() {
_config = utils.union(_config, arguments);
// main log method
- var _log = function(level, title, format, filters, args) {
+ var _log = function(level, title, format, filters, needstack, args) {
var msg = utils.format.apply(this, args);
var data = {
timestamp : dateFormat(new Date(), _config.dateformat),
@@ -29,14 +29,16 @@ module.exports = (function() {
};
data.method = data.path = data.line = data.pos = data.file = '';
- if (/{{(method|path|line|pos|file)}}/gi.test(format)) {
+ if (needstack) {
// get call stack, and analyze it
// get all file,method and line number
data.stack = (new Error()).stack.split('\n').slice(3);
// Stack trace format :
// http://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
- var s = data.stack[0], sp = /at\s+(.*)\s+\((.*):(\d*):(\d*)\)/gi.exec(s) || /at\s+()(.*):(\d*):(\d*)/gi.exec(s);
+ var s = data.stack[0], sp = /at\s+(.*)\s+\((.*):(\d*):(\d*)\)/gi
+ .exec(s)
+ || /at\s+()(.*):(\d*):(\d*)/gi.exec(s);
if (sp && sp.length === 5) {
data.method = sp[1];
data.path = sp[2];
@@ -92,6 +94,9 @@ module.exports = (function() {
var format = _config.format[0];
if (_config.format.length === 2 && _config.format[1][title])
format = _config.format[1][title];
+ var needstack = false;
+ if (/{{(method|path|line|pos|file)}}/gi.test(format))
+ needstack = true;
var filters;
if (lastFilter && lastFilter[title])
@@ -100,11 +105,13 @@ module.exports = (function() {
else
filters = _config.filters;
- _self[title] = (function(level, title, format, filters) {
+ _self[title] = (function(level, title, format, filters, needstack) {
return (function() {
- return _log(level, title, format, filters, arguments);
+ return _log(level, title, format, filters, needstack,
+ arguments);
});
- })(i, title, format, filters);
+
+ })(i, title, format, filters, needstack);
}
}
View
2 package.json
@@ -2,7 +2,7 @@
"name": "tracer",
"description": "A powerful and customizable logging library for node.js. support color console with timestamp, line number, method name, file name and call stack. you can set transport to file, stream, database(ex: mongodb and clouddb, simpledb). keywords: log, logger, trace ",
"homepage": "http://github.com/baryon/tracer",
- "version": "0.5.0",
+ "version": "0.5.1",
"author": "LI Long <lilong@gmail.com>",
"dependencies": {
"dateformat": "1.0.2-1.2.3",

0 comments on commit 6ed4997

Please sign in to comment.