Created
December 3, 2022 16:35
-
-
Save Madhusuthanan-B/b7ef8d877c75d9c52eb4ecaf3e73a4ba to your computer and use it in GitHub Desktop.
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
import winston from 'winston'; | |
// Format console.log | |
const consoleFormat = winston.format.printf(({ level, message }) => { | |
const logLevel = winston.format.colorize().colorize(level, level.toUpperCase()); | |
return `[${logLevel}: ${message}]`; | |
}); | |
// Logger | |
const logger = winston.createLogger({ | |
transports: [ | |
new winston.transports.Console({ | |
level: process.env.LOG_LEVEL, | |
handleExceptions: true, | |
format: winston.format.combine(winston.format.timestamp(), consoleFormat) | |
}) | |
] | |
}); | |
// Print unknown error | |
logger.on('error', (error) => { | |
console.log('Unknown Error Observed'); | |
console.log(error.message); | |
}); | |
export default logger; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment