Permalink
Browse files

minor-fix for call stack

  • Loading branch information...
1 parent 79ee090 commit 082dd42607d83ea3bc6898752d028818bedc5f45 @baryon committed Mar 8, 2012
Showing with 37 additions and 32 deletions.
  1. +4 −0 README.md
  2. +32 −31 lib/console.js
  3. +1 −1 package.json
View
@@ -347,6 +347,10 @@ module.exports = function(conf) {
## History
+### 0.3.1
+
+* minor-fix for call stack
+
### 0.3.0
* support custom format and filter for special method
View
@@ -22,15 +22,16 @@ module.exports = (function() {
}
return obj;
};
-
+
_config = _union(_config, arguments);
- _config.format = Array.isArray(_config.format) ? _config.format : [_config.format];
+ _config.format = Array.isArray(_config.format) ? _config.format
+ : [ _config.format ];
- var _isFunction = function (x) {
- return Object.prototype.toString.call(x) == '[object Function]';
+ var _isFunction = function(x) {
+ return Object.prototype.toString.call(x) == '[object Function]';
};
-
+
var _log = function(title, args) {
var msg = msgformat.apply(this, args);
var data = {
@@ -39,41 +40,40 @@ module.exports = (function() {
title : title
};
data.method = data.path = data.line = data.pos = data.file = '<unknown>';
- try {
- throw new Error();
- } catch (e) {
- data.stack = e.stack.split('\n').slice(3);
-
- var reg = /at\s+(.*)\s+\((.*):(\d*):(\d*)\)/ig;
- var sp = reg.exec(data.stack[0]);
- if (sp && sp.length === 5) {
- data.method = sp[1];
- data.path = sp[2];
- data.line = sp[3];
- data.pos = sp[4];
- var paths = data.path.split('/');
- data.file = paths[paths.length - 1];
- }
+
+ data.stack = (new Error()).stack.split('\n').slice(3);
+
+ var reg = /at\s+(.*)\s+\((.*):(\d*):(\d*)\)/ig;
+ var sp = reg.exec(data.stack[0]);
+ if (sp && sp.length === 5) {
+ data.method = sp[1];
+ data.path = sp[2];
+ data.line = sp[3];
+ data.pos = sp[4];
+ var paths = data.path.split('/');
+ data.file = paths[paths.length - 1];
}
+
var format = _config.format[0];
- if(_config.format.length===2 && _config.format[1][title])
+ if (_config.format.length === 2 && _config.format[1][title])
format = _config.format[1][title];
data.output = tim(format, data);
if (_config.filters) {
var filters = Array.isArray(_config.filters) ? _config.filters
- : [_config.filters];
- if (filters.length>0) {
+ : [ _config.filters ];
+ if (filters.length > 0) {
var i, len = filters.length;
- if(!_isFunction(filters[len-1])){
- len -= 1;
- if(filters[len][title]){
+ if (!_isFunction(filters[len - 1])) {
+ len -= 1;
+ if (filters[len][title]) {
filters = filters[len][title]
- filters = Array.isArray(filters) ? filters : [ filters ];
+ filters = Array.isArray(filters) ? filters
+ : [ filters ];
len = filters.length;
}
}
-
+
for (i = 0; i < len; i += 1) {
data.output = filters[i](data.output, data);
if (!data.output)
@@ -88,12 +88,13 @@ module.exports = (function() {
var _self = {};
var len = _config.methods.length;
- if(typeof(_config.level)=='string')
- _config.level=_config.methods.indexOf(_config.level);
+ if (typeof (_config.level) == 'string')
+ _config.level = _config.methods.indexOf(_config.level);
for ( var i = 0; i < len; ++i) {
var method = _config.methods[i];
if (i < _config.level)
- _self[method] = (function(){});
+ _self[method] = (function() {
+ });
else
_self[method] = (function(title) {
return (function() {
View
@@ -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.3.0",
+ "version": "0.3.1",
"author": "LI Long <lilong@gmail.com>",
"dependencies": {
"dateformat": "1.0.2-1.2.3",

0 comments on commit 082dd42

Please sign in to comment.