Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)')
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement