Comparing version 0.3.1 to 0.3.2
@@ -32,7 +32,7 @@ | ||
parent.setLogLevel(LogLevel.FINE); | ||
test.ok(child.isLoggable(LogLevel.FINE), 'FINE should be loggable for child'); | ||
test.ok(parent.isLoggable(LogLevel.FINE), 'FINE should be loggable for parent'); | ||
test.ok(!orphan.isLoggable(LogLevel.FINE), 'FINE should not be loggable for orphan'); | ||
test.done(); | ||
@@ -53,3 +53,3 @@ }; | ||
}); | ||
logger.info('test'); | ||
@@ -75,3 +75,3 @@ test.equal(1, records.length); | ||
logger.warn('test', [1, 2, 3]); | ||
test.equal('test', record.name); | ||
@@ -81,4 +81,30 @@ test.equal(LogLevel.WARN, record.level); | ||
test.equal('test [ 1, 2, 3 ]', record.message); | ||
test.done(); | ||
}; | ||
}; | ||
exports.testCloneWithNewMetadata = function(test) { | ||
var logger = new Logger('test').setMeta('extraField1', true); | ||
var newLogger = logger.clone().setMeta('extraField2', true); | ||
var record1 = null; | ||
var record2 = null; | ||
logger.registerWatcher(function(logRecord) { | ||
record1 = logRecord; | ||
}); | ||
newLogger.registerWatcher(function(logRecord) { | ||
record2 = logRecord; | ||
}); | ||
logger.warn('test'); | ||
test.ok(record1.meta.extraField1); | ||
test.ok(!record1.meta.extraField2); | ||
newLogger.warn('test'); | ||
test.ok(record2.meta.extraField1); | ||
test.ok(record2.meta.extraField2); | ||
test.done(); | ||
}; |
@@ -25,11 +25,4 @@ /** | ||
this.parent_ = null; | ||
this.watchers_ = []; | ||
this.logLevel_ = LogLevel.INHERIT; | ||
this.finest = this.log.bind(this, LogLevel.FINEST); | ||
this.finer = this.log.bind(this, LogLevel.FINER); | ||
this.fine = this.log.bind(this, LogLevel.FINE); | ||
this.info = this.log.bind(this, LogLevel.INFO); | ||
this.warn = this.log.bind(this, LogLevel.WARN); | ||
this.error = this.log.bind(this, LogLevel.SEVERE); | ||
this.info_ = null | ||
} | ||
@@ -59,2 +52,20 @@ util.inherits(Logger, EventEmitter); | ||
/** | ||
* Clone this logger, so that we can create a logger with different metadata. | ||
* @return {Logger} | ||
*/ | ||
Logger.prototype.clone = function () { | ||
var result = new Logger(this.name); | ||
result.parent_ = this.parent_; | ||
result.logLevel_ = this.logLevel_; | ||
if (this.info_) { | ||
result.info_ = {} | ||
for (var key in this.info_) { | ||
result.info_[key] = this.info_[key] | ||
} | ||
} | ||
return result; | ||
} | ||
/** | ||
* Sets the explicit log level for this logger. | ||
@@ -80,5 +91,7 @@ * @param {LogLevel} level | ||
* @param {Logger} logger | ||
* @return {Logger} For each chaining return this. | ||
*/ | ||
Logger.prototype.setParent = function(logger) { | ||
this.parent_ = logger; | ||
return this; | ||
}; | ||
@@ -102,2 +115,3 @@ | ||
* @param {string} value | ||
* @return {Logger} for chaining | ||
*/ | ||
@@ -107,2 +121,3 @@ Logger.prototype.setMeta = function(key, value) { | ||
this.info_[key] = value; | ||
return this; | ||
}; | ||
@@ -120,2 +135,39 @@ | ||
/** @param {*...} var_args The items to log at FINEST. */ | ||
Logger.prototype.finest = function (var_args) { | ||
this._log(LogLevel.FINEST, Array.prototype.slice.call(arguments, 0)); | ||
}; | ||
/** @param {*...} var_args The items to log at FINER. */ | ||
Logger.prototype.finer = function (var_args) { | ||
this._log(LogLevel.FINER, Array.prototype.slice.call(arguments, 0)); | ||
}; | ||
/** @param {*...} var_args The items to log at FINE. */ | ||
Logger.prototype.fine = function (var_args) { | ||
this._log(LogLevel.FINE, Array.prototype.slice.call(arguments, 0)); | ||
}; | ||
/** @param {*...} var_args The items to log at INFO. */ | ||
Logger.prototype.info = function (var_args) { | ||
this._log(LogLevel.INFO, Array.prototype.slice.call(arguments, 0)); | ||
}; | ||
/** @param {*...} var_args The items to log at WARN. */ | ||
Logger.prototype.warn = function (var_args) { | ||
this._log(LogLevel.WARN, Array.prototype.slice.call(arguments, 0)); | ||
}; | ||
/** @param {*...} var_args The items to log at ERROR. */ | ||
Logger.prototype.error = function (var_args) { | ||
this._log(LogLevel.SEVERE, Array.prototype.slice.call(arguments, 0)); | ||
}; | ||
/** | ||
@@ -127,4 +179,14 @@ * Logs at a specific level. | ||
Logger.prototype.log = function(level, var_args) { | ||
var logRecord = new LogRecord(level, this.name, this.info_, arguments); | ||
this._log(level, Array.prototype.slice.call(arguments, 1)); | ||
}; | ||
/** | ||
* Logs at a specific level. | ||
* @param {LogLevel} level | ||
* @param {Array} args The items to log. | ||
*/ | ||
Logger.prototype._log = function(level, args) { | ||
var logRecord = new LogRecord(level, this.name, this.info_, args); | ||
var rootLogger = Logger.getSingleton(); | ||
@@ -131,0 +193,0 @@ // |
@@ -11,3 +11,3 @@ | ||
this.meta = meta; | ||
this.rawArgs = Array.prototype.splice.call(args, 1).map(cloneErrors); | ||
this.rawArgs = args.map(cloneErrors); | ||
this.date = new Date; | ||
@@ -14,0 +14,0 @@ |
{ | ||
"name" : "logg", | ||
"version" : "0.3.1", | ||
"version" : "0.3.2", | ||
"description" : "Logging library that allows for hierarchical loggers, multiple log levels, and flexible watching of log records.", | ||
@@ -5,0 +5,0 @@ "keywords" : ["log", "logging", "logger", "hierarchical", "handler", "watcher"], |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
27969
639
1