Skip to content

Instantly share code, notes, and snippets.

@wonderb0lt
Created January 25, 2017 13:23
Show Gist options
  • Save wonderb0lt/b5528cd6083554d6e21d0d6562a5897d to your computer and use it in GitHub Desktop.
Save wonderb0lt/b5528cd6083554d6e21d0d6562a5897d to your computer and use it in GitHub Desktop.
Relative timestamps in winston
import winston from 'winston';
import {LOG_PATH} from './env';
let lastLog = new Date();
/**
* @type {winston.Logger}
*/
export default new winston.Logger({
transports: [
new winston.transports.Console({
prettyPrint: true,
colorize: true,
timestamp: () => {
const current = new Date();
const difference = current - lastLog;
lastLog = current;
return `+${difference}ms`
},
level: 'debug',
}),
new winston.transports.File({
filename: LOG_PATH,
maxsize: 40000,
maxFiles: 10,
}),
],
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment