light-logger
v1.0.4
Published
Light logger only console. Log level DEBUG, INFO, WARN, ERROR. Using namespace and timestamp.
Downloads
4
Maintainers
Readme
Installation
npm install light-logger
Example-1
var Logger = require('light-logger');
/**
* Default log level INFO
*/
var log = new Logger();
log.debug('Debug message');
log.log('Information message');
log.warn('Warning message');
log.err('Error message');
Output:
[21:53:12.357] [INFO] -> Information message [21:53:12.358] [WARN] -> Warning message [21:53:12.358] [ERR] -> Error message
Example-2
var Logger = require('light-logger');
/**
* Set namespace
* Set log level DEBUG
*/
var log = new Logger('Namespace','debug');
log.debug('Debug message');
log.log('Information message');
log.warn('Warning message');
log.err('Error message');
Output:
[21:54:14.442] [DEBUG] Namespace -> Debug message [21:54:14.446] [INFO] Namespace -> Information message [21:54:14.447] [WARN] Namespace -> Warning message [21:54:14.447] [ERR] Namespace -> Error message
Example-3
var Logger = require('light-logger');
/**
* Set namespace "Foo"
* Set log level WARN
* Logger enable
*/
var logger_1 = new Logger('Foo','warn',true);
/**
* Set namespace "Bar"
* Set log level DEBUG
* Logger enable
*/
var logger_2 = new Logger('Bar','debug',true);
logger_1.debug('Debug message');
logger_1.log('Information message');
logger_1.warn('Warning message');
logger_1.err('Error message');
logger_2.debug('Debug message');
logger_2.log('Information message');
logger_2.warn('Warning message');
logger_2.err('Error message');
Output:
[21:56:23.270] [WARN] Foo -> Warning message [21:56:23.270] [ERR] Foo -> Error message [21:56:23.271] [DEBUG] Bar -> Debug message [21:56:23.271] [INFO] Bar -> Information message [21:56:23.272] [WARN] Bar -> Warning message [21:56:23.272] [ERR] Bar -> Error message