wallet-core/node_modules/glogg/index.js

35 lines
538 B
JavaScript
Raw Normal View History

2016-10-10 03:43:44 +02:00
'use strict';
var format = require('util').format;
var sparkles = require('sparkles');
var levels = [
'debug',
'info',
'warn',
'error'
];
2018-09-20 02:56:13 +02:00
function getLogger(namespace) {
2016-10-10 03:43:44 +02:00
var logger = sparkles(namespace);
levels.forEach(function(level){
2018-09-20 02:56:13 +02:00
logger[level] = makeLogLevel(logger, level);
2016-10-10 03:43:44 +02:00
});
return logger;
}
2018-09-20 02:56:13 +02:00
function makeLogLevel(self, level) {
2016-10-10 03:43:44 +02:00
return function(msg){
2018-09-20 02:56:13 +02:00
if (typeof msg === 'string') {
2016-10-10 03:43:44 +02:00
msg = format.apply(null, arguments);
}
2018-09-20 02:56:13 +02:00
self.emit(level, msg);
2016-10-10 03:43:44 +02:00
};
}
module.exports = getLogger;