Created
May 30, 2023 08:38
-
-
Save kingbotss/f1d5d491bab4193a3e93c50f560e25c0 to your computer and use it in GitHub Desktop.
Winston logger nodejs script starter
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
| const { format, createLogger, transports } = require("winston"); | |
| const path=require('path'); | |
| const { combine, timestamp, label, printf } = format; | |
| const CATEGORY = "kingbotss"; | |
| //Using the printf format. | |
| const customFormat = printf(({ level, message, label, timestamp }) => { | |
| return `${timestamp} [${label}] ${level}: ${message}`; | |
| }); | |
| const logger = createLogger({ | |
| level: "info", | |
| format: combine(label({ label: CATEGORY }), timestamp(), customFormat), | |
| transports: [new transports.Console(),new transports.File({ | |
| filename: path.resolve( d+'/logs.log'), | |
| })], | |
| }); | |
| module.exports = logger; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Initiate logger
const logger=require('./logger');