-
Notifications
You must be signed in to change notification settings - Fork 0
/
winston.js
54 lines (51 loc) · 1.52 KB
/
winston.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import winston from 'winston'
import("winston-mongodb");
const { transports, format, createLogger } = winston
const { combine, printf } = format
// Create a timeStamp
const logTime = new Date().toLocaleDateString()
// Crate a custom log
const customLog = printf(({ level, message }) => {
return `Level:[${ level }] LogTime: [${ logTime }] Message:-[${ message }]`
})
const date = new Date()
const newdate = `${ date.getDate() }-${ date.getMonth() }-${ date.getFullYear() }`
const options = {
info: {
level: 'info',
dirname: 'logs/combibned',
json: true,
handleExceptions: true,
maxSize: '10',
filename: `combined-${ newdate }.log`,
datePattern: 'YYYY-MM-DD-HH',
}, dbinfo: {
level: "info",
collection: "deliveryLog",
db: process.env.MONGO_URI,
options: { useNewUrlParser: true, useUnifiedTopology: true },
maxsize: 52428800, // 50MB
},
error: {
level: 'error',
dirname: 'logs/error',
json: true,
handleExceptions: true,
filename: `error-${ newdate }.log`,
},
console: {
level: 'debug',
json: false,
handleExceptions: true,
colorize: true,
},
}
const logger = new createLogger({
format: combine(customLog), transports: [
new transports.File(options.info),
new transports.File(options.error),
new transports.MongoDB(options.dbinfo),
new transports.Console(options.console)
], exitOnError: false
})
export default logger