Add logger for application lifecycle
This commit is contained in:
parent
0c760dc303
commit
23ad99910f
1 changed files with 32 additions and 0 deletions
32
src/utils/logger.js
Normal file
32
src/utils/logger.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
import winston from "winston";
|
||||
|
||||
|
||||
const logger = () => {
|
||||
try {
|
||||
return winston.createLogger({
|
||||
level: 'info',
|
||||
format: winston.format.combine(
|
||||
winston.format.colorize(),
|
||||
winston.format.simple()
|
||||
),
|
||||
transports: [
|
||||
new winston.transports.Console(),
|
||||
new winston.transports.File({
|
||||
filename: 'logs/bot.log',
|
||||
options: { flags: 'a' },
|
||||
level: 'info',
|
||||
async: true
|
||||
})
|
||||
]
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Logger creation failed:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const log = logger();
|
||||
if (log) {
|
||||
log.info('Bot started');
|
||||
}
|
||||
|
||||
export { log };
|
Loading…
Add table
Add a link
Reference in a new issue