Skip to content

Commit

Permalink
updated to 0.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
baryon committed Jun 27, 2012
1 parent d33420a commit 6ed4997
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions example/format2.js
Expand Up @@ -18,6 +18,10 @@ var logger = require('tracer')
}

data.title = data.title.toUpperCase();

if(data.args[0]=='hello'){
data.message += ' node.js';
}
}
});

Expand Down
19 changes: 13 additions & 6 deletions lib/console.js
Expand Up @@ -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),
Expand All @@ -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];
Expand Down Expand Up @@ -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])
Expand All @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down

0 comments on commit 6ed4997

Please sign in to comment.