Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
186 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
var colors = require('colors'); | ||
|
||
function f1(str, data) { | ||
if( data.title === 'error' ){ | ||
// do some thing, ex: write to database | ||
|
||
// if you don't want continue other filter, then | ||
//return false; | ||
} | ||
return str.toUpperCase(); | ||
} | ||
|
||
var logger = require('tracer').colorConsole({ | ||
filters : [ | ||
f1, colors.underline, colors.blue, //default filter | ||
//the last item can be custom filter. here is "warn" and "error" filter | ||
{ | ||
warn : colors.yellow, | ||
error : [f1, colors.red, colors.bold ] | ||
} | ||
] | ||
}); | ||
|
||
logger.log('hello'); | ||
logger.trace('hello', 'world'); | ||
logger.debug('hello %s', 'world', 123); | ||
logger.info('hello %s %d', 'world', 123, {foo:'bar'}); | ||
logger.warn('hello %s %d %j', 'world', 123, {foo:'bar'}); | ||
logger.error('hello %s %d %j', 'world', 123, {foo:'bar'}, [1, 2, 3, 4], Object); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var logger = require('tracer') | ||
.colorConsole( | ||
{ | ||
format : [ | ||
"{{timestamp}} <{{title}}> {{message}} (in {{file}}:{{line}})", //default format | ||
{ | ||
error : "{{timestamp}} <{{title}}> {{message}} (in {{file}}:{{line}})\nCall Stack: {{stack}}" // error format | ||
} | ||
], | ||
dateformat : "HH:MM:ss.L" | ||
}); | ||
|
||
logger.log('hello'); | ||
logger.trace('hello', 'world'); | ||
logger.debug('hello %s', 'world', 123); | ||
logger.info('hello %s %d', 'world', 123, {foo : 'bar'}); | ||
logger.warn('hello %s %d %j', 'world', 123, {foo : 'bar'}); | ||
logger.error('hello %s %d %j', 'world', 123, {foo : 'bar'}, [ 1, 2, 3, 4 ], Object); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
2012-03-07T11:38:33.54Z <log> file.js:15 (Object.<anonymous>) hello | ||
2012-03-07T11:38:33.55Z <trace> file.js:16 (Object.<anonymous>) hello world | ||
2012-03-07T11:38:33.55Z <debug> file.js:17 (Object.<anonymous>) hello world 123 | ||
2012-03-07T11:38:33.55Z <info> file.js:18 (Object.<anonymous>) hello world 123 { foo: 'bar' } | ||
2012-03-07T11:38:33.55Z <warn> file.js:19 (Object.<anonymous>) hello world 123 {"foo":"bar"} | ||
2012-03-07T11:38:33.55Z <error> file.js:20 (Object.<anonymous>) hello world 123 {"foo":"bar"} [ 1, 2, 3, 4 ] function Object() { [native code] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters