-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLogManager.ts
35 lines (32 loc) · 1.05 KB
/
LogManager.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import winston from 'winston'
import fs from 'fs'
export class LogManager {
private logger: winston.Logger
constructor(private logDir: string, private datePattern: string, private env: string) {
if (!fs.existsSync(this.logDir)) {
fs.mkdirSync(this.logDir)
}
this.logger = winston.createLogger({
transports: [
new (winston.transports.Console)({
level: 'info'
}),
new (require('winston-daily-rotate-file'))({
filename: `${this.logDir}/logs`,
timestamp: this.tsFormat(),
datePattern: this.datePattern,
prepend: true,
level: this.env === 'development' ? 'verbose' : 'info',
maxFiles: '30d',
zippedArchive: true
})
]
})
}
tsFormat(): string {
return (new Date()).toLocaleDateString()
}
getLogger(): winston.Logger {
return this.logger
}
}