Permalink
Browse files

updated to 0.3.4, use tinytim package

  • Loading branch information...
1 parent 6158cf7 commit f773aea3ae4cace2848205b9a8113da15396f04d @baryon committed Mar 13, 2012
Showing with 22 additions and 59 deletions.
  1. +6 −1 README.md
  2. +10 −56 lib/console.js
  3. +3 −2 package.json
  4. +3 −0 test/test.js
View
@@ -128,6 +128,7 @@ format tag:
* timestamp: current time
* title: method name, default is 'log', 'trace', 'debug', 'info', 'warn', 'error'
+* level: method level, default is 'log':0, 'trace':1, 'debug':2, 'info':3, 'warn':4, 'error':5
* message: printf message, support %s string, %d number, %j JSON and auto inspect
* file: file name
* line: line number
@@ -137,7 +138,7 @@ format tag:
* stack: call stack
-About [Tim micro-template](https://github.com/premasagar/tim) and [Date Format](http://blog.stevenlevithan.com/archives/date-time-format)
+About [Tim micro-template](https://github.com/baryon/node-tinytim) and [Date Format](http://blog.stevenlevithan.com/archives/date-time-format)
```javascript
var logger = require('tracer').console(
@@ -347,6 +348,10 @@ module.exports = function(conf) {
## History
+### 0.3.4
+
+* use [tinytim package](https://github.com/baryon/node-tinytim)
+
### 0.3.3
* spell missing (transpot->transport)
View
@@ -1,3 +1,4 @@
+var tinytim = require('tinytim');
var dateFormat = require('dateformat');
module.exports = (function() {
@@ -28,12 +29,13 @@ module.exports = (function() {
_config = _union(_config, arguments);
// main log method
- var _log = function(title, format, filters, args) {
+ var _log = function(level, title, format, filters, args) {
var msg = msgformat.apply(this, args);
var data = {
timestamp : dateFormat(new Date(), _config.dateformat),
message : msg,
- title : title
+ title : title,
+ level : level
};
data.method = data.path = data.line = data.pos = data.file = '<unknown>';
@@ -52,15 +54,15 @@ module.exports = (function() {
}
// call micro-template to ouput
- data.output = tim(format, data);
+ data.output = tinytim.tim(format, data);
// process every filter method
var len = filters.length;
for ( var i = 0; i < len; i += 1) {
data.output = filters[i](data.output, data);
if (!data.output)
- return data;// cancel next process if return a false(include
- // null, undefined)
+ return data;
+ // cancel next process if return a false(include null, undefined)
}
// trans the final result
return _config.transport(data);
@@ -102,11 +104,11 @@ module.exports = (function() {
else
filters = _config.filters;
- _self[title] = (function(title, format, filters) {
+ _self[title] = (function(level, title, format, filters) {
return (function() {
- return _log(title, format, filters, arguments);
+ return _log(level, title, format, filters, arguments);
});
- })(title, format, filters);
+ })(i, title, format, filters);
}
}
@@ -148,51 +150,3 @@ function msgformat(f) {
}
return str;
}
-
-/*
- * ! Tim (lite) github.com/premasagar/tim
- *
- * A tiny, secure JavaScript micro-templating script.
- *
- * by Premasagar Rose dharmafly.com
- *
- * license opensource.org/licenses/mit-license.php *
- *
- * creates global object tim *
- *
- * v0.3.0
- *
- */
-
-var tim = (function() {
- "use strict";
-
- var start = "{{", end = "}}", path = "[a-z0-9_][\\.a-z0-9_]*", // e.g.
- // config.person.name
- pattern = new RegExp(start + "\\s*(" + path + ")\\s*" + end, "gi"), undef;
-
- return function(template, data) {
- // Merge data into the template string
- return template
- .replace(
- pattern,
- function(tag, token) {
- var path = token.split("."), len = path.length, lookup = data, i = 0;
-
- for (; i < len; i++) {
- lookup = lookup[path[i]];
-
- // Property not found
- if (lookup === undef) {
- throw "tim: '" + path[i]
- + "' not found in " + tag;
- }
-
- // Return the required value
- if (i === len - 1) {
- return lookup;
- }
- }
- });
- };
-}());
View
@@ -2,11 +2,12 @@
"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.3",
+ "version": "0.3.4",
"author": "LI Long <lilong@gmail.com>",
"dependencies": {
"dateformat": "1.0.2-1.2.3",
- "colors": ">=0.6.0"
+ "colors": ">=0.6.0",
+ "tinytim": ">=0.0.1"
},
"devDependencies": {
"expresso": "0.9.2",
View
@@ -83,10 +83,13 @@ exports["custom filter"] = function() {
});
var o = logger.log('hello %s %d', 'world', 123);
assert.equal(o['output'], '\u001b[4mhello world 123\u001b[24m');
+ assert.equal(o['level'], 0);
o = logger.warn('hello %s %d', 'world', 123);
assert.equal(o['output'], '\u001b[33mwarn:hello world 123\u001b[39m');
+ assert.equal(o['level'], 4);
o = logger.error('hello %s %d', 'world', 123);
assert.equal(o['output'], '\u001b[1m\u001b[31merror:hello world 123\u001b[39m\u001b[22m');
+ assert.equal(o['level'], 5);
}
exports["set level to log"] = function() {

0 comments on commit f773aea

Please sign in to comment.