Skip to content

royalpinto/pylogging

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pylogging

Pythonic way of logging for JavaScript

  • Implementation of python logging library http://docs.python.org/2/library/logging.html for JavaScript.
  • Highly customizable (visit examples).
  • Provides an interface for applications and other logging libraries.
  • Handlers to send log records (created by loggers) to the appropriate destination.
  • Filters to determine which log records to output.
  • Formatters to specify the layout of log records in the final output.

Installation

using npm:

npm install pylogging

Documentation

https://github.com/royalpinto/pylogging/tree/master/API.md

Examples

With default logger (the root logger)

var logging = require('pylogging');

logging.info('Info will be ignored as severity is set to logging.WARN.');
// <Prints nothing.>

logging.warn('I am warning.');
// WARN:root:I am warning.

logging.error('I am error: %s.', "Failed to get the data");
// ERROR:root:I am error: Failed to get the data.

With a module named logger instance with an handler.

var logging = require('./lib/main.js');

var logger = logging.getLogger('pylogging.examples');
logger.setLevel(logging.DEBUG); //Lets log everything.

// Create a console handler to write to the stdout/stderr.
var handler = new logging.ConsoleHandler();
handler.setLevel(logging.DEBUG);
handler.setFormatter(new logging.Formatter("%(levelname)s: %(msg)s\n"));

logger.addHandler(handler);

logger.info('Info will not be ignored as severity is set to logging.DEBUG.');
// Info will not be ignored as severity is set to logging.DEBUG.

logger.warn('I am warning.');
// WARN: I am warning.

logger.error('I am error: %s.', "Failed to get the data");
// ERROR: I am error: Failed to get the data.

For more examples and advance usage visit examples

About

Pythonic way of logging for JavaScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published