-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
42686f9
commit bc97a8f
Showing
3 changed files
with
102 additions
and
3 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { utilities, WinstonModule } from 'nest-winston'; | ||
import * as winston from 'winston'; | ||
import * as winstonDaily from 'winston-daily-rotate-file'; | ||
import { join } from 'path'; | ||
|
||
const { combine, timestamp, printf, colorize } = winston.format; | ||
|
||
const levels = { | ||
error: 0, | ||
warn: 1, | ||
info: 2, | ||
http: 3, | ||
debug: 4, | ||
} | ||
|
||
const colors = { | ||
error: 'red', | ||
warn: 'yellow', | ||
info: 'green', | ||
http: 'magenta', | ||
debug: 'blue', | ||
} | ||
|
||
winston.addColors(colors); | ||
|
||
// 로그 저장 경로 | ||
const logDir = join(__dirname, '../../logs'); | ||
|
||
// 로그 포맷 정의 | ||
const logFormat = printf(({ level, message, timestamp, stack }) => { | ||
return `${timestamp} ${level}: ${message} ${stack || ''}`; | ||
}); | ||
|
||
export const winstonConfig = { | ||
levels, | ||
transports: [ | ||
// 콘솔 출력 | ||
new winston.transports.Console({ | ||
level: process.env.NODE_ENV === 'production' ? 'info' : 'debug', | ||
format: combine( | ||
colorize({ all: true }), | ||
timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), | ||
utilities.format.nestLike('MyApp', { | ||
prettyPrint: true, | ||
colors: true, | ||
}), | ||
), | ||
}), | ||
|
||
// info 레벨 로그 파일 | ||
new winstonDaily({ | ||
level: 'info', | ||
datePattern: 'YYYY-MM-DD', | ||
dirname: join(logDir, 'info'), | ||
filename: `%DATE%.log`, | ||
maxFiles: 30, | ||
zippedArchive: true, | ||
format: combine( | ||
timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), | ||
logFormat, | ||
), | ||
}), | ||
|
||
// warn 레벨 로그 파일 | ||
new winstonDaily({ | ||
level: 'warn', | ||
datePattern: 'YYYY-MM-DD', | ||
dirname: join(logDir, 'warn'), | ||
filename: `%DATE%.warn.log`, | ||
maxFiles: 30, | ||
zippedArchive: true, | ||
format: combine( | ||
timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), | ||
logFormat, | ||
), | ||
}), | ||
|
||
// error 레벨 로그 파일 | ||
new winstonDaily({ | ||
level: 'error', | ||
datePattern: 'YYYY-MM-DD', | ||
dirname: join(logDir, 'error'), | ||
filename: `%DATE%.error.log`, | ||
maxFiles: 30, | ||
zippedArchive: true, | ||
format: combine( | ||
timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), | ||
logFormat, | ||
), | ||
}), | ||
], | ||
}; |
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