Giter Site home page Giter Site logo

node-just-logging's Introduction

just-logging

This module provides very simple logging, and nothing else, for nodejs modules.

There are so many logging framework that it was faster to write one than to find the right one for me. Usage and output kind of mimics log4j.

Installation

Install from npm:

npm install just-logging

Usage

Get a logger with the default name (the current module filename):

var logger = require('just-logging').getLogger();

Get a module with a specific name:

var logger = require('just-logging').getLogger('MY-LOGGER');

Log messages at different log levels:

logger.debug('Calibrating hyperplan gyroscopes...');

logger.info('Running system checks %d out of %d', i, total);

logger.warn('Polarization failure, switching to backup generator', error);

logger.warn('Catastrophic failure!', error);

With the default settings, this outputs the following:

[2012-09-23T07:04:37.990Z][WARN][6649][EngineSubSystem] Object.<anonymous>():14 Polarization failure, switching to backup generator [Error: null]
[2012-09-23T07:04:37.996Z][DEBUG][6649][EngineSubSystem] init():4 Calibrating hyperplan gyroscope...
[2012-09-23T07:04:37.997Z][INFO][6649][EngineSubSystem] runChecks():10 Running system checks 12 out of 287
[2012-09-23T07:04:37.997Z][ERROR][6649][EngineSubSystem] shutdown():18 Catastrophic failure! [Error: Divided by e^(pi * i) + 1]

Configuration

Level

The minimum level of the messages to log can be changed. Levels allowed are OFF, DEBUG, INFO, WARN, ERROR:

logger.level = 'WARN';

The level can also be changed for an other logger instance. For instance, to reduce or turn off a noisy module:

logger.getLogger('noisy-module.js').level = 'OFF';

Format

logger.format = '[%d{JSON}][%p][%t][%c] %M:%L %m';

Variables allowed in the format string:

  • %d: date

  • %d{FORMAT}: formatted date. Possible formats include:

    • JSON
    • ISOString
    • UTCString
    • DateString ...
  • %p: type (INFO, DEBUG, etc)

  • %t: process id

  • %c: logger name

  • %M: method name

  • %L: line number

  • %m: message

Contribute

github repository:

https://github.com/freongrr/node-just-logging

node-just-logging's People

Contributors

freongrr avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.