add line /caller info to log at "debug" level

This commit is contained in:
Matias Alejo Garcia 2014-10-06 16:51:40 -03:00
parent 923a0bb975
commit 0ef3dc86a7
2 changed files with 13 additions and 2 deletions

View File

@ -56,6 +56,7 @@ module.exports = function(grunt) {
files: [
'js/models/*.js',
'plugins/*.js',
'js/*.js',
],
tasks: ['shell:dev']
},

View File

@ -22,6 +22,7 @@ var Logger = function(name) {
this.level = 2;
};
var levels = {
'debug': 0,
'info': 1,
@ -34,9 +35,18 @@ var levels = {
_.each(levels, function(level, levelName) {
Logger.prototype[levelName] = function() {
if (level >= levels[this.level]) {
var str = '[' + levelName + '] ' + this.name + ': ' + arguments[0],
if (Error.stackTraceLimit && this.level == 'debug') {
Error.stackTraceLimit = 2
var stack = new Error().stack;
var lines = stack.split('\n');
var caller = lines[2];
caller = ':' + caller.substr(6);
}
var str = '[' + levelName + (caller||'') + '] ' + arguments[0],
extraArgs,
extraArgs = [].slice.call(arguments, 1);
extraArgs = [].slice.call(arguments, 1);
if (console[levelName]) {
extraArgs.unshift(str);
console[levelName].apply(console, extraArgs);