
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
debug-logger
Advanced tools
A thin wrapper for visionmedia/debug logger, adding levels and colored output.
visionmedia/debug is a ubitiquous logging library with 1000+ dependants. Given how widespread it is and the convenience of namespaces it is a great logger for library modules.
debug-logger
is a convenience wrapper around debug
that adds level based coloured output. Each instance of debug-logger
will lazily instantiate several instances of debug
such as namespace:info
, namespace:warn
, namespace:error
, etc. All these are configurable. debug-logger
has no dependencies besides debug
.
At AppsCot we use debug-logger
in waterline-orientdb.
npm install debug-logger -S
var log = require('debug-logger')('myapp');
log.trace("I'm a trace output");
log.debug("I'm a debug output");
log.log("I'm a log output");
log.info("I'm an info output");
log.warn("I'm a warn output");
log.error("I'm an error output");
var err = new Error('error message');
err.stack = 'the stack\nline2\nline3';
log.error('Something failed:', err);
var obj = {
anumber : 1234,
astring : 'str',
adate : new Date(),
aboolean : true
};
log.info("let's inspect 'obj'", obj);
debug
instances and enabled propertylog.debug.logger()("the debug instance of debug, using 'myapp:debug' namespace");
var debug = debugLogger.debug('myapp:visionmedia');
debug('Nothing tastes better than the original!');
if (log.debug.enabled()) {
// This only runs if environment variable DEBUG includes "myapp:debug" namespace
log.debug("Debug is enabled");
}
Full util.inspect
options available at nodejs.org.
var debugLogger = require('debug-logger');
debugLogger.inspectOptions = {
colors : true
};
log.info('By enabling colors we get this nice colored example:', {
anumber : 1234,
astring : 'str',
adate : new Date(),
aboolean : true
});
debugLogger.levels.error.color = debugLogger.colors.magenta;
debugLogger.levels.error.prefix = 'ERROR ';
var customColorLog = debugLogger('myapp');
customColorLog.error("I'm a 'magenta' error output");
debugLogger.levels.silly = {
color : debugLogger.colors.magenta,
prefix : 'SILLY ',
namespaceSuffix : ':silly'
};
var sillyLog = debugLogger('myapp');
sillyLog.silly("I'm a silly output");
log.log("Multiple", "arguments", "including", "objects:", { obj: 'obj'}, "makes life easier");
log.warn("util.format style string: %s, number: %d and json: %j.", "foo", 13, { obj: 'json'});
export DEBUG_LEVEL=info
Only info level and above logs will be outputted.
More examples in the examples folder.
Assuming log is an instance of debug-logger (var log = require('debug-logger')('myapp');
).
log.trace([data][, ...])
log.debug([data][, ...])
log.log([data][, ...])
log.info([data][, ...])
log.warn([data][, ...])
log.error([data][, ...])
Prints the data prepended by log level. If the terminal supports colors, each level will have a specific color. If an Error is provided, the toString() and call stack will be outputted. If an Object is provided the toString() and util.inspect() will be outputted. Example:
myapp:debug I'm a debug output +0ms
myapp:info I'm an info output +1ms
This function can take multiple arguments in a printf()-like way, if formatting elements are not found in the first string then util.inspect is used on each argument.
log[level].logger()
Returns the default debug instance used by level
.
log[level].enabled()
Boolean indicating if level
's logger is enabled.
.config(obj)
Configures debug-logger. Returns debug-logger
to allow chaining operations.
.debug
Returns visionmedia/debug module.
FAQs
A wrapper for visionmedia/debug logger, adding levels and colored output
The npm package debug-logger receives a total of 2,879 weekly downloads. As such, debug-logger popularity was classified as popular.
We found that debug-logger demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.