Skip to content

Commit a64a60d

Browse files
committed
feat: config winston
1 parent e4764ac commit a64a60d

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/config/winston.ts

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { formatDate } from 'helpers/Date'
2+
import path from 'path'
3+
import winston from 'winston'
4+
5+
// define the custom settings for each transport (file, console)
6+
const options = {
7+
file: {
8+
level: 'info',
9+
filename: `${path.resolve('./logs')}/log-${formatDate(new Date())}.log`,
10+
handleExceptions: true,
11+
json: true,
12+
maxsize: 5242880, // 5MB
13+
maxFiles: 5,
14+
colorize: false,
15+
},
16+
console: {
17+
level: 'debug',
18+
handleExceptions: true,
19+
json: false,
20+
colorize: true,
21+
},
22+
}
23+
24+
// instantiate a new Winston Logger with the settings defined above
25+
const winstonLogger = winston.createLogger({
26+
format: winston.format.json(),
27+
transports: [
28+
//
29+
// - Write all logs with level `error` and below to `error.log`
30+
// - Write all logs with level `info` and below to `combined.log`
31+
//
32+
new winston.transports.File(options.file),
33+
new winston.transports.Console(options.console),
34+
],
35+
exitOnError: false,
36+
})
37+
38+
// create a stream object with a 'write' function that will be used by `morgan`
39+
export const winstonStream = {
40+
write: (message: string) => {
41+
winstonLogger.info(message)
42+
},
43+
}

0 commit comments

Comments
 (0)