Comparing version 0.2.0 to 0.2.1
@@ -46,2 +46,3 @@ /** | ||
var msg = color + logRecord.message + colReset; | ||
var info = logRecord.meta ? (';' + logRecord.getFormattedMeta()) : '' | ||
@@ -51,3 +52,3 @@ var now = getDateString(logRecord.date); | ||
var out = colGrey + now + (logRecord.name ? ' [' + | ||
colReset + logRecord.name + colGrey + ']' : '') + ' : ' + | ||
colReset + logRecord.name + colGrey + info + ']' : '') + ' : ' + | ||
colReset + msg; | ||
@@ -54,0 +55,0 @@ |
@@ -37,5 +37,7 @@ /** | ||
/** @type {?Logger} The Logger singleton instance */ | ||
Logger._instance = null; | ||
/** | ||
@@ -55,2 +57,3 @@ * Static function that returns a singleton instance of the | ||
/** | ||
@@ -93,2 +96,15 @@ * Sets the explicit log level for this logger. | ||
/** | ||
* Sets logger level info which will be written with each log line. This is | ||
* useful for loggers that are scoped to a particular task, for example, a | ||
* request scoped logger that shows user id and client request. | ||
* @param {string} key | ||
* @param {string} value | ||
*/ | ||
Logger.prototype.setMeta = function(key, value) { | ||
if (!this.info_) this.info_ = {}; | ||
this.info_[key] = value; | ||
}; | ||
/** | ||
* Registers a log watchers on this logger. | ||
@@ -107,3 +123,3 @@ * @param {function(LogRecord)} watcher | ||
Logger.prototype.log = function(level, var_args) { | ||
var logRecord = new LogRecord(level, this.name, arguments); | ||
var logRecord = new LogRecord(level, this.name, this.info_, arguments); | ||
@@ -110,0 +126,0 @@ var rootLogger = Logger.getSingleton(); |
@@ -7,5 +7,6 @@ | ||
function LogRecord(level, name, args) { | ||
function LogRecord(level, name, meta, args) { | ||
this.level = level; | ||
this.name = name; | ||
this.meta = meta; | ||
this.rawArgs = Array.prototype.splice.call(args, 1).map(cloneErrors); | ||
@@ -17,2 +18,12 @@ this.date = new Date; | ||
LogRecord.prototype.getFormattedMeta = function () { | ||
if (!this.meta) return '' | ||
var out = [] | ||
for (var key in this.meta) { | ||
out.push(key + '=' + this.meta[key]) | ||
} | ||
return out.join(',') | ||
} | ||
LogRecord.prototype.getFormattedMessage = function () { | ||
@@ -19,0 +30,0 @@ var args = this.rawArgs.map(function(a) { |
{ | ||
"name" : "logg", | ||
"version" : "0.2.0", | ||
"version" : "0.2.1", | ||
"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"], |
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
25402
564