Last active
November 16, 2023 20:03
-
-
Save broskisworld/c1366391d22b3d79ea7819d5fbcd724a to your computer and use it in GitHub Desktop.
Winston quickstart file with a daily rotating log file, colorization, timestamp prefix, and log level prefix
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
// PACKAGES | |
const winston = require('winston'); | |
const { format } = require('logform'); | |
require('winston-daily-rotate-file'); | |
const simpleTimestampAndLevel = format.printf(({ level, message, timestamp }) => { | |
return `${timestamp} ${level}: ${message}`; | |
}); | |
const simpleLevel = format.printf(({ level, message }) => { | |
return `${level}: ${message}`; | |
}); | |
const logger = winston.createLogger({ | |
transports: [ | |
new winston.transports.Console({ | |
format: format.combine( | |
format.colorize(), | |
simpleLevel | |
), | |
level: 'debug' | |
}), | |
new winston.transports.DailyRotateFile({ | |
filename: './logs/%DATE%.log', | |
datePattern: 'YYYY-MM-DD', | |
zippedArchive: true, | |
maxSize: '20m', | |
maxFiles: '14d', | |
format: format.combine( | |
format.timestamp(), | |
simpleTimestampAndLevel | |
), | |
level: 'silly' | |
}), | |
] | |
}); | |
module.exports = logger; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment