Skip to content

Commit

Permalink
Update logging config
Browse files Browse the repository at this point in the history
  • Loading branch information
Byunk committed Dec 24, 2023
1 parent bc25542 commit d794c37
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/config/winston.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import winston from 'winston';
import winstonDaily from 'winston-daily-rotate-file';
import DailyRotateFile from 'winston-daily-rotate-file';
import path from 'path';

let logger: winston.Logger;

Expand All @@ -22,31 +23,31 @@ if (process.env.NODE_ENV !== 'production') {
} else {
logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
defaultMeta: { service: 'user-service' },
format: winston.format.combine(
winston.format.timestamp({
format: 'YYYY-MM-DD HH:mm:ss',
}),
winston.format.json(),
),
defaultMeta: { service: 'bai' },
transports: [
//
// - Write all logs with importance level of `error` or less to `error.log`
// - Write all logs with importance level of `info` or less to `combined.log`
//
new winston.transports.File({
dirname: 'logs',
filename: 'error.log',
level: 'error',
new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
consoleFormat,
),
}),

new winston.transports.Console(),

new winstonDaily({
new DailyRotateFile({
filename: 'trace-%DATE%.log',
level: 'info',
dirname: 'logs',
dirname: path.join(__dirname, '../../logs'),
datePattern: 'YYYY-MM-DD-HH',
maxSize: '20m',
maxFiles: '30d',
}),
],
});
}
logger.info("logger initialized")

export default logger;

0 comments on commit d794c37

Please sign in to comment.