Comparing version 0.0.5 to 0.0.6
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
var Logger = require('../') | ||
@@ -8,4 +10,4 @@ , logger = new Logger; | ||
logger.info('info message with object', {}); | ||
logger.notice('sending a notice', 1, 2, 3) | ||
logger.metric('already send', logger.calls, 'logs') | ||
logger.notice('sending a notice', 1, 2, 3); | ||
logger.metric('already send', logger.calls, 'logs'); | ||
logger.warning('odear, we are going to break something'); | ||
@@ -29,3 +31,7 @@ logger.error('something bad happend'); | ||
logger.on('error', function (args, stack) { | ||
console.log('There was an error logged at line: ' + stack[0].getLineNumber()); | ||
console.log('There was an error logged at line: ' + (stack | ||
? stack[0].getLineNumber() | ||
: 'unknown' | ||
)); | ||
}); | ||
@@ -24,3 +24,3 @@ "use strict"; | ||
var rs = Object.prototype.toString.call(prop); | ||
return rs.slice(8, rs.length - 1).toLowerCase() | ||
return rs.slice(8, rs.length - 1).toLowerCase(); | ||
} | ||
@@ -137,6 +137,7 @@ | ||
this.calls = 0; | ||
this.silence = {}; | ||
// do we need to supply a default logging library? | ||
if (this.base) { | ||
this.use(require('../transports/stream')) | ||
this.use(require('../transports/stream')); | ||
} | ||
@@ -163,7 +164,119 @@ }; | ||
if (args.length) envs = args; | ||
if ('all' == envs || ~envs.indexOf(this.env)) fn && fn.call(this); | ||
if (fn && ('all' === envs || ~envs.indexOf(this.env))) fn.call(this); | ||
return this; | ||
}; | ||
/** | ||
* Update an setting. | ||
* | ||
* @param {String} key the setting to update | ||
* @param {Mixed} value the new value | ||
* @api public | ||
*/ | ||
Logger.prototype.set = function set (key, value) { | ||
if (key in this) { | ||
if (value !== this[key]) this.emit('settings:' + key, value); | ||
this[key] = value; | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Returns the setting for the given key | ||
* | ||
* @param {String key | ||
* @returns {Mixed} | ||
* @api public | ||
*/ | ||
Logger.prototype.get = function get (key) { | ||
return this[key]; | ||
}; | ||
/** | ||
* Check if the setting is enabled. | ||
* | ||
* @param {String} key | ||
* @returns {Boolean} | ||
*/ | ||
Logger.prototype.enabled = function enabled (key) { | ||
return !!this.get(key); | ||
}; | ||
/** | ||
* Check if the setting is disabled. | ||
* | ||
* @param {String} key | ||
* @returns {Boolean} | ||
* @api public | ||
*/ | ||
Logger.prototype.disabled = function disabled (key) { | ||
return !this.get(key); | ||
}; | ||
/** | ||
* Enables the given setting. | ||
* | ||
* @param {String} key | ||
* @api public | ||
*/ | ||
Logger.prototype.enable = function enable (key) { | ||
return this.set(key, true); | ||
}; | ||
/** | ||
* Disables the given setting. | ||
* | ||
* @param {String} key | ||
* @api public | ||
*/ | ||
Logger.prototype.disabled = function disabled (key) { | ||
return this.set(key, true); | ||
}; | ||
/** | ||
* Allows you to ignore log message from a given file name. | ||
* | ||
* @param {String} file | ||
* @api public | ||
*/ | ||
Logger.prototype.ignore = function ignore (file) { | ||
this.silence[file] = 1; | ||
return this; | ||
}; | ||
/** | ||
* Stop ignoring the given file name. | ||
* | ||
* @api public | ||
*/ | ||
Logger.prototype.unignore = function unignore (file) { | ||
if (file in this.silence) delete this.silence[file]; | ||
return this; | ||
}; | ||
/** | ||
* Returns a list currently ignored files. | ||
* | ||
* @returns {Array} | ||
* @api public | ||
*/ | ||
Logger.prototype.ignoring = function ignoring () { | ||
return Object.keys(this.silence); | ||
}; | ||
/** | ||
* Add more transport methods to the logger. | ||
@@ -187,2 +300,3 @@ * | ||
/** | ||
@@ -248,6 +362,17 @@ * Test if a transport is available. | ||
, length = this.transports.length | ||
, i = 0; | ||
, i = 0 | ||
, path | ||
, filename; | ||
if (stack) { | ||
path = stack[0].getFileName(); | ||
filename = path.slice(path.lastIndexOf('/') + 1); | ||
// silence, silence! ssht! | ||
if (this.silence[filename]) return this; | ||
} | ||
for (; i < length; i++) { | ||
this.transports[i].write(type, this.namespace(stack, args), args); | ||
this.transports[i].write(type, this.namespace(stack, args, filename), args); | ||
} | ||
@@ -279,3 +404,3 @@ | ||
var now = date || new Date; | ||
return this.pattern.replace(/{(.+?)(?::(.*?))?}/g, function (res, method, padding) { | ||
return this.pattern.replace(/\{(.+?)(?::(.*?))?\}/g, function (res, method, padding) { | ||
for (res = now[method in now ? method : 'get' + method]() // exec the getter | ||
@@ -320,3 +445,3 @@ + (/h/.test(method) || '') // increment month by 1 | ||
i = 1 | ||
i = 1; | ||
str = f.replace(formatRegExp, function (x) { | ||
@@ -355,2 +480,3 @@ if (i >= len) return x; | ||
* @param {Mixed} arg first "normal" argument that the logger received | ||
* @param {String} filename the filename where the log message originates from | ||
* @returns {String} namespace | ||
@@ -360,27 +486,33 @@ * @api private | ||
Logger.prototype.namespace = function namespace (trace, args) { | ||
if (!trace || !trace.length) return ''; | ||
Logger.prototype.namespace = function namespace (trace, args, filename) { | ||
if (!trace || !trace.length) return []; | ||
var arg = args[0] | ||
, filename = trace[0].getFileName().split('/').pop() | ||
, one, two; | ||
, one, two | ||
, path = [filename]; | ||
// try to detect if we received a user defined namespace argument or | ||
if (args.length > 1 // we should have multiple arguments | ||
&& typeof arg == 'string' // first should be string | ||
&& !~arg.indexOf(' ') // but not a sentance | ||
&& !~arg.indexOf('%') // and not a formatting option | ||
if (args.length > 1 // we should have multiple arguments | ||
&& typeof arg === 'string' // first should be string | ||
&& !~arg.indexOf(' ') // but not a sentance | ||
&& !~arg.indexOf('%') // and not a formatting option | ||
) { | ||
return filename + '/' + args.shift(); | ||
path.push(args.shift()); | ||
return path; | ||
} | ||
// generate a namespace from the called functions | ||
one = trace[0].getFunctionName() || trace[0].getMethodName() | ||
two = one && trace[1] ? trace[1].getFunctionName() || trace[1].getMethodName() : false; | ||
one = trace[0].getFunctionName() || trace[0].getMethodName(); | ||
// and compile a namespace from the function names | ||
return filename + (one | ||
? '/' + one + (two ? '/' + two : '') | ||
: '' | ||
) | ||
if (one) { | ||
path.push(one); | ||
if (trace[1]) { | ||
two = trace[1].getFunctionName() || trace[1].getMethodName(); | ||
if (two) path.push(two); | ||
} | ||
} | ||
// return the code path | ||
return path; | ||
}; | ||
@@ -402,3 +534,3 @@ | ||
, 'if ('+ index +' > this.level) return this;' | ||
, 'if ('+ index +' > this.namespacing) {' | ||
, 'if ('+ index +' < this.namespacing) {' | ||
, ' original = Error.prepareStackTrace;' | ||
@@ -433,3 +565,3 @@ , ' Error.prepareStackTrace = function (idontgiveafuck, trace) { return trace; };' | ||
Logger.version = '0.0.5'; | ||
Logger.version = '0.0.6'; | ||
@@ -436,0 +568,0 @@ /** |
{ | ||
"name": "devnull" | ||
, "version": "0.0.5" | ||
, "version": "0.0.6" | ||
, "description": "A simple logger with automatic function detection." | ||
@@ -14,7 +14,7 @@ , "homepage": "http://observer.no.de" | ||
"colors": "0.5.1" | ||
, "mongodb": "" | ||
, "mongodb": "0.9.7-2-3" | ||
} | ||
, "devDependencies": { | ||
"mocha": "*" | ||
, "should": "*" | ||
, "should": "0.3.2" | ||
, "long-stack-traces": "0.1.2" | ||
@@ -21,0 +21,0 @@ } |
@@ -65,2 +65,3 @@ # dev/null because logging to dev/null is webscale | ||
- **notification** At what log level should we start emitting events? Default is 1. | ||
- **namespacing** At what log level should we start generating namespaces (uses callsite based stacktraces)? Defaults to 8. | ||
- **timestamp** Should we prepend a timestamp to the log message? Logging is always done asynchronously so it might be that log messages do not appear in order. A timestamp helps you identify the order of the logs. Default is true. | ||
@@ -67,0 +68,0 @@ - **pattern** The pattern for the timestamp. Everybody prefers it's own pattern. The pattern is based around the great [140bytes date entry](https://gist.github.com/1005948) but also allows functions to be called directly. Default is the util.log format that Node.js adopted. |
@@ -6,2 +6,3 @@ /**! | ||
*/ | ||
var should = require('should') | ||
@@ -516,2 +517,74 @@ describe('dev/null, logger', function () { | ||
}) | ||
describe('#get', function () { | ||
it('should return the value for the given key', function () { | ||
var logger = new Logger | ||
logger.get('env').should.equal(logger.env) | ||
logger.get('pattern').should.equal(logger.pattern) | ||
}) | ||
it('should return nothing for unknown keys', function () { | ||
var logger = new Logger | ||
should.not.exist(logger.get('trolololol')) | ||
}) | ||
}) | ||
describe('#set', function () { | ||
it('should set values', function () { | ||
var logger = new Logger | ||
logger.set('env', 'testing') | ||
logger.get('env').should.equal('testing') | ||
}) | ||
it('should only set values for existing keys', function () { | ||
var logger = new Logger | ||
logger.set('aaaaa', 12) | ||
should.not.exist(logger.get('aaaaa')) | ||
}) | ||
it('should emit an event when a new value is set', function (next) { | ||
var logger = new Logger | ||
logger.on('settings:env', function (value) { | ||
value.should.equal('testing') | ||
next() | ||
}) | ||
logger.set('env', 'testing') | ||
}) | ||
it('should not emit an event when the value stays the same', function (next) { | ||
var logger = new Logger | ||
logger.on('settings:env', function (value) { | ||
should.fail() | ||
}) | ||
logger.set('env', logger.get('env')) | ||
setTimeout(next, 10) | ||
}) | ||
}) | ||
describe('#enabled', function () { | ||
it('should be enabled', function () { | ||
var logger = new Logger | ||
logger.enabled('base').should.be.true | ||
logger.enabled('timestamp').should.be.true | ||
}) | ||
it('should not be enabled', function () { | ||
var logger = new Logger | ||
logger.set('timestamp', false) | ||
logger.set('base', false) | ||
logger.enabled('base').should.be.false | ||
logger.enabled('timestamp').should.be.false | ||
}) | ||
}) | ||
}) |
@@ -14,3 +14,3 @@ /**! | ||
get: function () { | ||
return stream || (stream = require('./stream')) | ||
return stream || (stream = require('./stream')); | ||
} | ||
@@ -26,3 +26,3 @@ }); | ||
get: function () { | ||
return mongodb || (mongodb = require('./mongodb')) | ||
return mongodb || (mongodb = require('./mongodb')); | ||
} | ||
@@ -38,4 +38,4 @@ }); | ||
get: function () { | ||
return transport || (transport = require('./transport')) | ||
return transport || (transport = require('./transport')); | ||
} | ||
}); |
@@ -30,3 +30,3 @@ "use strict"; | ||
this.stream = null; | ||
} | ||
}; | ||
@@ -94,3 +94,3 @@ /** | ||
}); | ||
} | ||
}; | ||
@@ -163,3 +163,3 @@ /** | ||
self.logger.emit('transport:write', log); | ||
}) | ||
}); | ||
}); | ||
@@ -166,0 +166,0 @@ }; |
@@ -32,3 +32,3 @@ "use strict"; | ||
this.name = 'streamer'; | ||
} | ||
}; | ||
@@ -54,3 +54,3 @@ /** | ||
+ ' (' | ||
+ namespace | ||
+ (namespace ? namespace.join('/') : '/') | ||
+ ') ' | ||
@@ -81,5 +81,5 @@ + this.logger.format.apply(this, args) | ||
if (this.stream.end) { | ||
try { this.stream.end() } | ||
try { this.stream.end(); } | ||
catch (e) {} | ||
} | ||
}; |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
var EventEmitter = process.EventEmitter; | ||
@@ -13,3 +15,3 @@ | ||
var rs = Object.prototype.toString.call(prop); | ||
return rs.slice(8, rs.length - 1).toLowerCase() | ||
return rs.slice(8, rs.length - 1).toLowerCase(); | ||
} | ||
@@ -74,2 +76,2 @@ | ||
Transport.prototype.close = function close () {} | ||
Transport.prototype.close = function close () {}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
54572
1520
1
198
+ Addedmongodb@0.9.7-2-3(transitive)
- Removed@mongodb-js/saslprep@1.1.9(transitive)
- Removed@types/webidl-conversions@7.0.3(transitive)
- Removed@types/whatwg-url@11.0.5(transitive)
- Removedbson@6.9.0(transitive)
- Removedmemory-pager@1.5.0(transitive)
- Removedmongodb@6.10.0(transitive)
- Removedmongodb-connection-string-url@3.0.1(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedsparse-bitfield@3.0.3(transitive)
- Removedtr46@4.1.1(transitive)
- Removedwebidl-conversions@7.0.0(transitive)
- Removedwhatwg-url@13.0.0(transitive)
Updatedmongodb@0.9.7-2-3