Comparing version 0.0.2 to 0.0.3
@@ -5,3 +5,3 @@ "use strict"; | ||
* dev/null | ||
* @copyright (c) 2011 Observer (observer.no.de) <info@3rd-Eden.com> | ||
* @copyright (c) 2011 Observe.it (observe.it) <arnout@observe.com> | ||
* MIT Licensed | ||
@@ -16,2 +16,15 @@ */ | ||
/** | ||
* Strict type checking. | ||
* | ||
* @param {Mixed} prop | ||
* @returns {String} | ||
* @api private | ||
*/ | ||
function type (prop) { | ||
var rs = Object.prototype.toString.call(prop); | ||
return rs.slice(8, rs.length - 1).toLowerCase() | ||
} | ||
/** | ||
* Detect if can use colors or not. | ||
@@ -88,2 +101,3 @@ * | ||
* - `pattern` pattern for the timestamp, defaults to node's util log format. | ||
* - `base` do we need to provide a base transport by default?, default to true. | ||
* | ||
@@ -101,3 +115,2 @@ * @constructor | ||
this.levels = levels; | ||
this.level = Object.keys(this.levels).length; | ||
this.level = options.level || Object.keys(this.levels).length; | ||
@@ -107,8 +120,13 @@ this.notification = this.levels.warning; | ||
// output related options | ||
this.timestamp = true | ||
this.timestamp = true; | ||
this.base = true; | ||
this.pattern = '{FullYear}-{Month:2}-{Date:2} {toLocaleTimeString}'; | ||
// override the defaults | ||
// override the defaults, but not the methods and they should also be the | ||
// exact same type | ||
for (var key in options) { | ||
if (key in this) { | ||
if (key in this | ||
&& type(this[key]) !== 'function' | ||
&& type(this[key]) === type(options[key]) | ||
) { | ||
this[key] = options[key]; | ||
@@ -121,2 +139,8 @@ } | ||
this.transports = []; | ||
this.calls = 0; | ||
// do we need to supply a default logging library? | ||
if (this.base) { | ||
this.use(require('../transports/stream')) | ||
} | ||
}; | ||
@@ -127,2 +151,22 @@ | ||
/** | ||
* Allow different or multiple transports per enviroument by placing it in | ||
* a configure function. | ||
* | ||
* @param {String} env NODE_ENV result | ||
* @param {Function} fn callback | ||
* @api public | ||
*/ | ||
Logger.prototype.configure = function configure (env, fn) { | ||
var envs = 'all' | ||
, args = [].slice.call(arguments); | ||
fn = args.pop(); | ||
if (args.length) envs = args; | ||
if ('all' == envs || ~envs.indexOf(this.env)) fn && fn.call(this); | ||
return this; | ||
}; | ||
/** | ||
* Add more transport methods to the logger. | ||
@@ -138,5 +182,7 @@ * | ||
// prevent duplicates | ||
if (this.has(Transport)) return this; | ||
if (this.has(Transport) | ||
|| type(Transport) !== 'function' | ||
) return this; | ||
this.transports.push(new Transport(this, options)); | ||
this.transports.push(new Transport(this, options || {})); | ||
return this; | ||
@@ -157,3 +203,5 @@ }; | ||
while (i--) { | ||
if (this.transports[i] instanceof Transport) return this.transports[i]; | ||
if (this.transports[i] instanceof Transport | ||
|| this.transports[i] === Transport | ||
) return this.transports[i]; | ||
} | ||
@@ -180,7 +228,7 @@ | ||
// shutdown the transport | ||
transport.shutdown(); | ||
transport.close(); | ||
// and remove it | ||
while (i--) { | ||
if (this.transport[i] === transport) { | ||
if (this.transports[i] === transport) { | ||
this.transports.splice(i, 1); | ||
@@ -208,18 +256,14 @@ } | ||
// iterate of all available transports and give them theh shizzle | ||
console[type in console ? type : 'log'].apply( | ||
console | ||
, [ | ||
this.stamp() | ||
+ ' ' | ||
+ this.prefix[type] | ||
+ ' (' + this.namespace(stack, args) + ')' | ||
].concat(args) | ||
); | ||
for (var i = 0, length = this.transports.length; i < length; i++) { | ||
this.transports[i].write(type, this.namespace(stack, args), args); | ||
} | ||
// do we need to emit a event | ||
if (level <= this.notify) { | ||
if (level <= this.notification) { | ||
this.emit(type, args, stack); | ||
} | ||
// increase our calls | ||
++this.calls; | ||
return this; | ||
@@ -320,3 +364,2 @@ }; | ||
Logger.prototype.namespace = function (trace, args) { | ||
var stack = trace.split('\n').slice(2, 4) | ||
@@ -330,4 +373,3 @@ , namespace = [] | ||
// try to detect if we received a user defined namespace argument or | ||
// try to detect if we received a user defined namespace argument or | ||
if (args.length > 1 // we should have multiple arguments | ||
@@ -387,2 +429,4 @@ && typeof arg == 'string' // first should be string | ||
* | ||
* @TODO we might want to check for the log level here instead of in the write | ||
* function to eleminate a function call and stack generation | ||
* @api private | ||
@@ -401,6 +445,33 @@ */ | ||
}); | ||
/** | ||
* Start exporting some additional information like log levels etc. Most of the | ||
* details is already exposed but we might as well, expose all the things. | ||
*/ | ||
/** | ||
* Versioning. | ||
* | ||
* @type {String} | ||
* @api public | ||
*/ | ||
Logger.version = "0.0.2"; | ||
Logger.version = '0.0.3'; | ||
/** | ||
* Export the logging methods which are used to prefix the output. | ||
* | ||
* @type {Object} | ||
* @api public | ||
*/ | ||
Logger.methods = methods; | ||
/** | ||
* Log levels, type:level. | ||
* | ||
* @type {Object} | ||
* @api public | ||
*/ | ||
Logger.levels = levels; |
{ | ||
"name": "devnull" | ||
, "version": "0.0.2" | ||
, "version": "0.0.3" | ||
, "description": "A simple logger with automatic function detection." | ||
@@ -12,3 +12,14 @@ , "homepage": "http://observer.no.de" | ||
} | ||
, "dependencies": { | ||
"colors": "0.5.1" | ||
} | ||
, "devDependencies": { | ||
"mocha": "*" | ||
, "should": "0.3.2" | ||
, "long-stack-traces": "0.1.2" | ||
} | ||
, "main": "index" | ||
, "scripts": { | ||
"test": "make test" | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
37370
16
1065
1
3
1
2
+ Addedcolors@0.5.1
+ Addedcolors@0.5.1(transitive)