Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

I added the stack trace support to logger. #1

Open
wants to merge 2 commits into from

1 participant

hlj
hlj

No description provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 20, 2011
  1. added stack track support

    hlj authored
Commits on Jun 15, 2011
  1. hlj

    fix stacktrace level

    hlj authored
This page is out of date. Refresh to see the latest.
Showing with 18 additions and 1 deletion.
  1. +18 −1 logger.js
19 logger.js
View
@@ -42,6 +42,11 @@ var Logger = function(log_file_path) {
// default write is STDOUT
this.write = sys.print;
this.log_level_index = 3;
+ //default output stack trace
+ this.stackTrace = true;
+ //reduce unnecessary trace by the filter string.
+ //for example,set the filter equal your application's root path name to output the caller at your project only.
+ this.stackTraceFilter = null;
// if a path is given, try to write to it
if (log_file_path) {
@@ -95,7 +100,19 @@ Logger.prototype.log = function() {
}
});
message = this.format(Logger.levels[log_index], new Date(), message);
- this.write(message + "\n");
+ var stackstr = '';
+ if (this.stackTrace && log_index < 2) {
+ var stack = new Error().stack.split('\n');
+ var self = this;
+ stackstr = stack.filter(function(v){
+ if (v.indexOf('].log') > -1) return false;
+ if (self.stackTraceFilter) {
+ return v.indexOf(self.stackTraceFilter)>-1;
+ }
+ return true;
+ }).join('\n') + '\n';
+ }
+ this.write(message + "\n" +stackstr);
return message;
}
return false;
Something went wrong with that request. Please try again.