Skip to content

Instantly share code, notes, and snippets.

@mudivili mudivili/Logger-helper
Last active Dec 18, 2017

Embed
What would you like to do?
const pino = require('pino');
const config = require('config');
const logger = pino({level: config.logLevel});
exports.getLogger = function getLogger(module) {
return logger.child({ module: module });
};
exports.getMethodEndLogger = function getMethodEndLogger(logger, method, input) {
let startTime = process.hrtime();
logger.info({method: method, input: input});
function methodEndLog(error, result) {
let timeDifference = process.hrtime(startTime);
let milliseconds = timeDifference[1] / 1000000;
if(error) {
return logger.error({method: method, input: input, error: error, responseTime: milliseconds});
}
logger.info({method: method, input: input, result: result, responseTime: milliseconds});
}
return methodEndLog;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.