New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

logg

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

logg

Logging library that allows for hierarchical loggers, multiple log levels, and flexible watching of log records.

0.1.2
Version published
Weekly downloads
43
437.5%
Maintainers
1
Weekly downloads
 
Created

Node-Logging

This is a logging library for use with node.js. It decouples log reporting from publishing and is based on the Java API.

Installation

Fork the latest source from github.

or

npm install logg

Usage

Call getLogger(name) with the name of your class, namespace, or made up identifier.

Loggers expose fine(), info(), warn(), error() and log(level, args). These logging methods take variable arguments and will call sys.inspect on any objects that are passed. There is special handling for Error objects.

var logging = require('logg');

var logger = logging.getLogger('my.class);
logger.setLogLevel(logging.Level.WARN);
logger.info('This will not show up');
logger.warn('But warnings will', new Error('aargg')); 

Loggers are arranged in a hierarchy based on their names, separated by dots. Log reporting levels are inherited based on the hierarchy, INFO being the default level. For example, the following will silence everything but errors within the subproject namespace:

var a = logging.getLogger('project.subproject.foo');
var b = logging.getLogger('project.subproject.bar');
var c = logging.getLogger('project.subproject.baz');
var d = logging.getLogger('project.subproject.bam');

logging.getLogger('project.subproject').setLogLevel(logging.Level.SEVERE);

Every logger can have watchers associated with it, which will get called with a log record. Usually you'd just want to attach to root logger.

logging.registerWatcher(function(logRecord) {
  // Don't use sync API in real life...
  fs.writeFileSync('logs.log', JSON.stringify(logRecord) + '\n');
});

A default watcher is automatically registered which outputs to the console.

FAQs

Package last updated on 25 Jul 2012

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