Created
March 18, 2019 21:55
-
-
Save SeanCannon/25f91473277ee1d944f5159d3f5f3983 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const R = require('ramda'), // 0.26.1 | |
winston = require('winston'); // 2.4.x | |
const winstonConf = { | |
transports : [ | |
{ | |
transportType : 'console' | |
} | |
], | |
strategies : { | |
console : winston.transports.Console | |
} | |
}; | |
const getTransportInstances = R.curry((winstonConf, transportConfig) => { | |
const transportConstructor = winstonConf.strategies[transportConfig.transportType]; | |
return new (transportConstructor)(transportConfig); | |
}); | |
const logger = new (winston.Logger)({ | |
transports : winstonConf.transports.map(getTransportInstances(winstonConf)) | |
}); | |
const appendMetaToEveryLog = (logType, meta) => { | |
return R.partialRight(R.bind(logger[logType], logger), [{ meta }]); | |
}; | |
const decorateInfoLogForPerformanceMetrics = meta => R.compose( | |
R.partial(appendMetaToEveryLog('info', meta)), | |
R.append(R.__, []), | |
R.concat('PERFORMANCE TIMER ') | |
); | |
module.exports = meta => ({ | |
error : appendMetaToEveryLog('error', meta), | |
info : appendMetaToEveryLog('info', meta), | |
debug : appendMetaToEveryLog('debug', meta), | |
warn : appendMetaToEveryLog('warn', meta), | |
perfStart : decorateInfoLogForPerformanceMetrics(meta)('START'), | |
perfEndSuccess : decorateInfoLogForPerformanceMetrics(meta)('END (SUCCESS)'), | |
perfEndFail : decorateInfoLogForPerformanceMetrics(meta)('END (FAIL)') | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment