bouquins/lib/util/logger.js
Meutel 0d0f564475 Project creation
boostrap: start webserver, router catches requests
routeur: create outputter and endpoint, trigger actions
outputter: write in specified format
action: act on resource
2014-01-19 14:37:31 +01:00

29 lines
684 B
JavaScript

/**
* TODO license
* Basic logger.
*/
var logger = exports;
logger.debugLevel = 'debug';
logger.log = function(level, message) {
var levels = ['fatal', 'error', 'warn', 'info', 'debug'];
if (levels.indexOf(level) <= levels.indexOf(logger.debugLevel) ) {
if (typeof message !== 'string') {
message = JSON.stringify(message);
};
console.log(new Date().toISOString() + ' [' + level+'] '+message);
}
}
logger.debug = function(message) {
logger.log('debug', message);
}
logger.info = function(message) {
logger.log('info', message);
}
logger.error = function(message) {
logger.log('error', message);
}
logger.fatal = function(message) {
logger.log('fatal', message);
}