public
dewd / bad
Last active

excerpts from a working, but ugly, common logger

  • Download Gist
bad
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
module: ./lib/logger
---------------------------
 
// load config file (would like this to be passed in to the constructor)
nconf.file({ file: fileConfig});
var logSetting = nconf.get('log');
 
// instantiate the logger
var log = new Bunyan({
name: logSetting.name,
streams : [
{ stream : process.stdout,
level : logSetting.stdoutLevel},
{ path : logSetting.logfile,
level : logSetting.logfileLevel}
],
serializers : Bunyan.stdSerializers
});
 
function Logger(options) {
};
 
Logger.prototype.info = function info(e) { log.info(e) };
Logger.prototype.debug = function debug(e) { log.debug(e) };
Logger.prototype.trace = function trace(e) { log.trace(e) };
Logger.prototype.error = function error(e) { log.error(e) };
Logger.prototype.warn = function warn(e) { log.warn(e) };
 
module.exports = Logger;
 
 
 
module: main app
----------------------------------------
// create the logger
var logger = require('./lib/logger)
var log = new logger(options);
 
 
module: any project module using logger
-----------------------------------------
// open the logger (new, rely on singleton...)
var logger = require('./lib/logger');
var log = new logger();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.