Skip to content

bonte-nicolas/eklogger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Eklogger

A Lightweight logger that combines namespacing, levels and multi output.

Installation

Installing packages

  $ npm install

Usage

The logger must be initialized with one or many namespace and a level.

For use it, just instantiating a logger with a namespace and call a log function.

There are 5 level. Each level has a specific integer priority. The logger can't output if the log level isn't bigger than logger level ( setLevel() ).

{ trace: 0, debug: 1, info: 2, warn: 3, error: 4 }

Example app.js

    const logger = require('./index');
    
    logger.setNamespaces('namespace:*');
    logger.setLevel('debug');
    
    const log = logger('namespace:subNamespace');
    log.debug('Will be logged', {someData: 'someValue', someData2: 'someValue'});

output :

Example

Recommended Usage

The logger can have a specifier context id.

Example app.js

    const logger = require('./index');
    
    logger.setNamespaces('namespace:*');
    logger.setLevel('debug');
    
    const log = logger('namespace:subNamespace');
    log.debug('ctxId', 'Will be logged', {someData: 'someValue', someData2: 'someValue'});

output :

Example

Logging Namespace

The logger can have many namespace. If the log namespace isn't in logger namespace list, the logger can't output. For enable or disable a namespace, use setNamespace function.

Enabling and Disabling Logging Namespaces

  logger.setNamespaces('namespace:*, -namespace:wrongSubNamespace');
  logger.setLevel('debug');
  
  const log = logger('namespace:subNamespace');
  const log2 = logger('namespace:wrongSubNamespace');
  log.debug("Will be logged");
  log2.info("Will not be logged");
    logger.setNamespaces('*, -wrongNamespace');
    logger.setLevel('debug');
    
    const log = logger('namespace:subNamespace');
    const log2 = logger('wrongNamespace');
    log.debug("Will be logged");
    log2.info("Will not be logged");

Using Logging Namespaces

  logger.setNamespaces('namespace:*');
  logger.setLevel('debug');
  
  const log = logger('namespace:subNamespace');
  const log2 = logger('wrongNamespace:subNamespace');
  log.debug("Will be logged");
  log2.info("Will not be logged");
  logger.setNamespaces('namespace:subNamespace');
  logger.setLevel('debug');
  
  const log = logger('namespace:subNamespace');
  const log2 = logger('namespace:wrongSubNamespace');
  log.debug("Will be logged");
  log2.info("Will not be logged");

Logging Output

The logger have two output type. Available values are "pretty" or "json". Default is json

JSON

  const logger = require('./index');
      
  logger.setNamespaces('namespace:*');
  logger.setLevel('debug');
  //logger.setOutput('json');
      
  const log = logger('namespace:subNamespace');
  log.debug('ctxId', 'Will be logged',{someData: 'someValue', someData2: 'someValue'});

output :

Example

Pretty

  const logger = require('./index'&);
      
   logger.setNamespaces('namespace:*');
   logger.setLevel('debug');
   logger.setOutput('pretty');
   
   const log = logger('namespace:subNamespace');
   log.debug('ctxId', 'Will be logged',{someData: 'someValue', someData2: 'someValue'});

output :

Example

Data

A logger should write a Json Object with expected data.

    logger.setNamespaces('namespace:*');
    logger.setLevel('info');
    
    const log = logger('namespace:subNamespace');
    
    log.warn('message', { someData: 'someValue' });

contextId

    logger.setNamespaces('namespace:*');
    logger.setLevel('info');
    
    const log = logger('namespace:subNamespace');
    
    log.warn('ctxId', 'message');
    log.error('ctxId', 'message', { someData: 'someValue' });

Tests

Run Tests

  $ make test

About

A Lightweight logger that combines debug namespacing capabilities with winston levels and multioutput

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors