Socket
Socket
Sign inDemoInstall

modulelog

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    modulelog

Library to allow easy userland-changeable logging for node modules/applications


Version published
Weekly downloads
5
Maintainers
1
Install size
11.0 kB
Created
Weekly downloads
 

Changelog

Source

0.2.2 ###

  • Added setClass and setLevel static methods

Readme

Source

modulelog

A library that allows easy userland swapping of different logging libraries.

By default it uses the built-in util.debuglog but any npm module can be required and used, provided it has at least some of warn, info, error, debug methods that it exposes on its exports. console can also be used, except that no debug methods will be logged.

Usage

var log = require('modulelog')('mymodulename');
log.setClass('console');
function cb(err) {
    log.error("An error occured", {error: err});
}

A common use case would be to use flags and allow the user to pass the class name via --logger:

var log = require('modulelog')('mymodulename'),
    flags = require('flags');
flags.defineString('logger', 'debug', 'Your name');
flags.parse();
log.setClass(flags.get('logger'));

Methods

Note: you must pass your module/app name to the result of require('modulelog') in order to get an instance to log with. The actual class and level is globally controlled across modules but each module must have a name for the debuglog prefix.

log.setClass(name)

Change the default logging library to be name. Built-in values are default, debuglog, console. If an empty string is passed in, all logs will be discarded. Any non-built-in values will be passed to require.

log.setLevel(level)

Calls setLevel on the backing library. If the library doesn't support different levels (like debuglog or console) then this does nothing.

log.debug(msg[, extra]...)

log.info(msg[, extra]...)

log.warn(msg[, extra]...)

log.error(msg[, extra]...)

Calls the corresponding method on the backing library. It is recommended that you call with message and an object of extra data, however any number of arguments are accepted and passed on.

log.fatal(msg[, extra]...)

Calls the corresponding method on the backing library. If the library has no fatal method, then error is called instead. After logging, process.exit is invoked.

Static Methods

If you're trying to set the level or class in a static fashion setLevel and setClass are both exposed statically on the exports for the module.

Keywords

FAQs

Last updated on 18 Feb 2016

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc