Created
January 25, 2017 13:23
-
-
Save wonderb0lt/b5528cd6083554d6e21d0d6562a5897d to your computer and use it in GitHub Desktop.
Relative timestamps in winston
This file contains hidden or 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
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