Skip to content

Commit

Permalink
Update logger.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Apr 8, 2024
1 parent ad21268 commit 3966d97
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions api/src/common/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import winston, { format, transports } from 'winston'

const production = process.env.NODE_ENV === 'production'
const logFormat = format.printf((info) => `${info.timestamp} ${info.level}: ${info.message}`)
const level = production ? 'info' : 'debug'

const logger = winston.createLogger({
level: production ? 'info' : 'debug',
level,
format: format.combine(
format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
format.errors({ stack: true }),
Expand All @@ -18,12 +19,8 @@ const logger = winston.createLogger({
logFormat,
),
}),
//
// - Write all logs with importance level of `error` or less to `logs/error.log`
// - Write all logs with importance level of `info` or less to `logs/all.log`
//
new transports.File({ filename: 'logs/error.log', level: 'error', format: logFormat }),
new transports.File({ filename: 'logs/all.log', format: logFormat }),
new transports.File({ filename: 'logs/all.log', level, format: logFormat }),
],
})

Expand Down

0 comments on commit 3966d97

Please sign in to comment.