Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

debug-logger

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

debug-logger

A wrapper for visionmedia/debug logger, adding levels and colored output

  • 0.3.1
  • npm
  • Socket score

Version published
Weekly downloads
4.9K
increased by1.58%
Maintainers
1
Weekly downloads
 
Created
Source

npm version

debug-logger

A thin wrapper for visionmedia/debug logger, adding levels and colored output.

Overview

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 3 instances of debug, one for general purpose logging using namespace, another for debug (namespace:debug) and another for trace (namespace:trace). All this in configurable fashion. debug-logger has no dependencies besides debug.

At AppsCot we use debug-logger in waterline-orientdb.

Instalation

npm install debug-logger -S

Usage

var log = require('debug-logger')('myapp');

log.debug("I'm a debug output");
log.info("I'm an info output");
log.warn("I'm a warn output");
log.error("I'm an error output");

screenshot

Inspect error/object

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);

inspect error/object

Original debug instances and enabled property

log.info.logger()("the default instance of debug, using 'myapp' namespace");
log.debug.logger()("the debug instance of debug, using 'myapp:debug' namespace");

if (log.debug.enabled()) {
  // This only runs if environment variable DEBUG includes "myapp:debug" namespace
  log.debug("Debug is enabled");
}

enabled

util.inspect options

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
});

inspect

Customize available log levels

debugLogger.levels.error.color = debugLogger.getForeColor('magenta');
debugLogger.levels.debug.color = debugLogger.getBackColor('cyan') + debugLogger.getForeColor('white');

var customColorLog = debugLogger('myapp');
customColorLog.error("I'm a 'magenta' error output");
customColorLog.debug("I'm a 'cyan'/'white' debug output");

customize log

Add log levels

debugLogger.levels.silly = {
  color : debugLogger.getForeColor('magenta'),
  prefix : 'SILLY  ',
  namespaceSuffix : ':silly'
};

var sillyLog = debugLogger('myapp');
sillyLog.silly("I'm a silly output");

add log levels

Filter log level (instead of namespace)

export DEBUG_LEVEL=info

Only info level and above logs will be outputted.

More examples in the examples folder.

Reference

Instance Methods

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, the level will be one of: blue, green, yellow, red. 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 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.

Module

.getForeColor(color)

Returns an ANSI foreground color code string. color is one of black, red, green, yellow, blue, magenta, cyan, white Example:

  debugLogger.getForeColor('cyan')
  // returns '\x1b[36m'
.getBackColor(color)

Returns an ANSI background color code string.

.debug

Returns visionmedia/debug module.

Keywords

FAQs

Package last updated on 26 Feb 2015

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc