Comparing version 0.1.3 to 0.1.4
@@ -5,10 +5,10 @@ | ||
exports.testGetLogger = function(test) { | ||
exports.testGetLogger = function (test) { | ||
var first = logg.getLogger('first'); | ||
var firstFoo = logg.getLogger('first.foo'); | ||
var someOther = logg.getLogger('some.Other'); | ||
test.strictEqual(first.getParent(), logg.rootLogger); | ||
test.strictEqual(firstFoo.getParent(), first); | ||
test.equals(someOther.getParent().name, 'some'); | ||
@@ -18,3 +18,3 @@ test.done(); | ||
exports.testNothing = function(test) { | ||
exports.testNothing = function (test) { | ||
// Just log stuff to the console. | ||
@@ -25,3 +25,3 @@ var first = logg.getLogger('first'); | ||
first.setLogLevel(0); | ||
firstFoo.error('This is severe!!!'); | ||
@@ -31,4 +31,22 @@ firstFoo.warn('This is a warning'); | ||
first.fine('Everything is fine fine fine'); | ||
test.done(); | ||
test.done(); | ||
}; | ||
exports.testTransientLogger = function (test) { | ||
var foo = logg.getLogger('foo') | ||
var first = logg.getTransientLogger('foo.bar'); | ||
var second = logg.getTransientLogger('foo.bar'); | ||
test.notStrictEqual(first, second, 'Instance should be different.'); | ||
test.strictEqual(first.getParent(), foo, 'Parent should be foo') | ||
test.strictEqual(first.getParent(), second.getParent(), 'Parents should be the same') | ||
var third = logg.getLogger('foo.bar') | ||
test.notStrictEqual(first, third, 'Instance should be different.'); | ||
first.info('Testing transient') | ||
second.info('Testing another transient') | ||
third.info('Testing standard') | ||
test.done() | ||
}; |
@@ -10,11 +10,3 @@ /** | ||
/** | ||
* The log levels. | ||
* @type {!Object} | ||
*/ | ||
exports.Level = require('./level'); | ||
/** | ||
* Map of loggers. Use a global so that it is shared if multiple copies of the | ||
@@ -32,6 +24,6 @@ * library are loaded, i.e. by using submodules or their own node_modules | ||
/** | ||
* Reference to the root loger. | ||
* Reference to the root logger. | ||
* @type {!Logger} | ||
*/ | ||
var rootLogger = exports.rootLogger = LOGGERS['']; | ||
var rootLogger = LOGGERS['']; | ||
@@ -45,20 +37,53 @@ | ||
*/ | ||
var getLogger = exports.getLogger = function(ns) { | ||
function getLogger(ns) { | ||
if (!LOGGERS[ns]) { | ||
LOGGERS[ns] = new Logger(ns); | ||
LOGGERS[ns].setParent(getLogger(ns.substr(0, ns.lastIndexOf('.')))); | ||
LOGGERS[ns].setParent(getLogger(getParentNs(ns))); | ||
} | ||
return LOGGERS[ns]; | ||
}; | ||
} | ||
/** | ||
* Returns a new transient logger each time it is called. | ||
* | ||
* Transient loggers that will not be globally registered and can thus be garbage | ||
* collected when they go out of scope. Unlike getLogger(), calling this method | ||
* twice will return two separate instances. It can also not be used to control | ||
* log levels of child loggers. | ||
* | ||
* If parent loggers exist, they will be used, otherwise transient parents will | ||
* be created. As such transient loggers can inherit log levels from the root | ||
* logger. | ||
* | ||
* @param {string} ns The logger namespace, e.g. foo.bar.baz | ||
* @return {!Logger} | ||
*/ | ||
function getTransientLogger(ns) { | ||
var logger = new Logger(ns); | ||
var parent = getParentNs(ns); | ||
if (LOGGERS[parent]) logger.setParent(LOGGERS[parent]) | ||
else logger.setParent(getTransientLogger(parent)) | ||
return logger | ||
} | ||
/** | ||
* Registers a watch function on the root logger. | ||
* @param {function(LogRecord)} watcher | ||
*/ | ||
var registerWatcher = exports.registerWatcher = function(watcher) { | ||
function registerWatcher(watcher) { | ||
rootLogger.registerWatcher(watcher); | ||
}; | ||
} | ||
/** | ||
* Gets the parent namespace. | ||
* @param {string} ns The logger namespace, e.g. foo.bar.baz | ||
* @return {string} The parent's namespace, e.g. foo.bar | ||
*/ | ||
function getParentNs(ns) { | ||
return ns.substr(0, ns.lastIndexOf('.')) | ||
} | ||
if (isRoot) { | ||
@@ -68,1 +93,10 @@ // Register a default watcher that just logs to the console. | ||
} | ||
module.exports = { | ||
Level: require('./level'), | ||
rootLogger: rootLogger, | ||
getLogger: getLogger, | ||
getTransientLogger: getTransientLogger, | ||
registerWatcher: registerWatcher | ||
} | ||
{ | ||
"name" : "logg", | ||
"version" : "0.1.3", | ||
"version" : "0.1.4", | ||
"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
15594
437