Permalink
Browse files

updated to 0.5.0, added config.js stress.js examples

  • Loading branch information...
1 parent 79464c9 commit ce41ab1544b2f7908ac2e60d56ad044e5c9fa177 @baryon committed Jun 22, 2012
Showing with 120 additions and 18 deletions.
  1. +4 −0 README.md
  2. +33 −0 example/config.js
  3. +49 −0 example/stress.js
  4. +17 −16 lib/console.js
  5. +1 −1 package.json
  6. +16 −1 test/test.js
View
@@ -380,6 +380,10 @@ module.exports = function(conf) {
## History
+### 0.5.0
+
+* performance: speed up when the format don't include method,path,line,pos,file, thanks sharonjl's issue report
+
### 0.4.2
* fixed: debug color from blue to cyan
View
@@ -0,0 +1,33 @@
+var conf = {
+ log_dev : {
+ strategy : 'colorConsole',
+ setting : {
+ level : 'log'
+ }
+ },
+ log_prd : {
+ strategy : 'console',
+ setting : {
+ level : 'warn'
+ }
+ }
+};
+
+var tracer = require('tracer')
+
+function test(c){
+ var logger = tracer[c.strategy](c.setting);
+ logger.log('hello');
+ logger.trace('hello', 'world');
+ logger.debug('hello %s', 'world', 123);
+ logger.warn('hello %s', 'world', 123);
+ logger.error('hello %s', 'world', 123);
+}
+
+
+test(conf.log_dev);
+
+test(conf.log_prd);
+
+
+
View
@@ -0,0 +1,49 @@
+// Run as:
+// $> node stress.js
+
+function stress_log(log) {
+ var i;
+ for (i = 0; i < 100000; ++i) {
+ log.info("Counter Value = %s", i);
+ }
+}
+
+function test_tracer() {
+ var log = require('tracer').console({
+ transport : function(data) {}
+ });
+
+ console.time('test_tracer');
+ stress_log(log);
+ console.timeEnd('test_tracer');
+}
+
+
+function test_tracer_skip() {
+ var log = require('tracer').console({
+ level:"warn",
+ transport : function(data) {}
+ });
+
+ console.time('test_tracer_skip');
+ stress_log(log);
+ console.timeEnd('test_tracer_skip');
+}
+
+
+function test_tracer_nostack() {
+ //if the format don't include "method|path|line|pos|file", the speed will be up
+ var log = require('tracer').console({
+ format: "{{timestamp}} <{{title}}> {{message}}",
+ transport : function(data) {}
+ });
+
+ console.time('test_tracer_nostack');
+ stress_log(log);
+ console.timeEnd('test_tracer_nostack');
+}
+
+test_tracer();
+test_tracer_skip();
+test_tracer_nostack();
+
View
@@ -28,24 +28,26 @@ module.exports = (function() {
};
data.method = data.path = data.line = data.pos = data.file = '';
- // 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]
- , _reg1 = /at\s+(.*)\s+\((.*):(\d*):(\d*)\)/ig, _reg2 = /at\s+()(.*):(\d*):(\d*)/ig
- , sp = _reg1.exec(s) || _reg2.exec(s);
- 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];
+ if (/{{(method|path|line|pos|file)}}/gi.test(format)) {
+ // 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);
+ 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];
+ }
}
_config.preprocess(data);
-
+
// call micro-template to ouput
data.output = tinytim.tim(format, data);
@@ -107,4 +109,3 @@ module.exports = (function() {
return _self;
});
-
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.4.2",
+ "version": "0.5.0",
"author": "LI Long <lilong@gmail.com>",
"dependencies": {
"dateformat": "1.0.2-1.2.3",
View
@@ -1,5 +1,19 @@
var assert = require("assert");
+exports["simple"] = function() {
+ var logger = require('../').console({
+ transport : function(data) {
+ console.log(data.output);
+ return data;
+ }
+ });
+ var o = logger.info('hello');
+ assert.equal(o['message'], 'hello');
+ assert.equal(o['file'], 'test.js');
+ assert.equal(o['line'], 10);
+ assert.equal(o['level'], 3);
+}
+
exports["simple message"] = function() {
var logger = require('../').console({
format : "{{message}}",
@@ -12,6 +26,7 @@ exports["simple message"] = function() {
assert.equal(o['output'], 'hello');
}
+
exports["simple color message"] = function() {
var logger = require('../').colorConsole({
format : "{{message}}",
@@ -34,7 +49,7 @@ exports["console log method"] = function() {
});
var o = logger.log('hello %s %d', 'world', 123);
assert.equal(o['title'], 'log');
- assert.equal(o['file'], 'test.js');
+ assert.equal(o['file'], '');//the format don't include "file", so can't get it
assert.equal(o['output'], 'hello world 123');
}

0 comments on commit ce41ab1

Please sign in to comment.