js-logger icon indicating copy to clipboard operation
js-logger copied to clipboard

Add Support for Cascading LogLevel Configuration

Open jonnyreeves opened this issue 12 years ago • 1 comments

JSLogger should cascade the LogLevel configuration for named loggers based on their namespace, so for example:

var loggerA = Logger.get("parentNS.clientA");

// Configure the LogLevel of the parent namespace Logger.get("parentNS").setLevel(Logger.WARN);

loggerA.info("Info Message"); // No output loggerA.warn("Warning Message"): // Logs "Warning Message"

This feature would provide developers a way to express log levels for an entire group of clients without having to manually list them all out.

jonnyreeves avatar Jan 04 '13 09:01 jonnyreeves

You could have a look at how debug does this.

Debug has no global logger, only named loggers. And it is basically just a list, there is no hierarchy. But it can simulate hierarchy through naming conventions. They recommend using colon : to separate levels:

var debug = require('debug')
var log = require('my-app:my-module')
log('Hello!')

By default, this would not produce any output, but you can enable loggers using a pattern:

debug.enable('my-app:my-module') // enables only the one module
debug.enable('my-app:*') // enables every submodule of my-app

They translate the pattern and then use simple regex pattern matching on the name to determine if the logger is enabled or not. It works surprisingly well.

Download avatar Mar 10 '19 12:03 Download