-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwinstonlogger.js
128 lines (100 loc) · 3.05 KB
/
winstonlogger.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const winston = require('winston')
const CSV_FILENAME = "cfcrmigrationpipelines.csv";
const fs = require('fs');
dateFormat = () => {
return new Date(Date.now()).toUTCString()
}
class LoggerService {
// outputfolder='.'
constructor(outputfolder) {
try {
console.log("outputfolder-->",outputfolder);
fs.rename(outputfolder+CSV_FILENAME, outputfolder+"prev_cfcrmigrationpipelines.csv", (err) => {
// if (err) throw err;
console.log(`current csv fle renamed to ${outputfolder}/prev_cfcrmigrationpipelines.csv`);
});
} catch (err) {
console.log("current csv fle rename error.May not exists yet");
}
const logger = winston.createLogger({
transports: [
// new winston.transports.Console(),
new winston.transports.File({
filename: `${outputfolder}/cfcrmigrationpipelines.csv`
})
],
format: winston.format.printf((info) => {
// // let message = `${dateFormat()} | ${info.level.toUpperCase()} | ${route}.log | ${info.message} | `
// message = info.pipid+","
// let message = info.obj ? `${JSON.stringify(info.obj)} | ` : "notvalidcsv"
// // message = this.log_data ? message + `log_data:${JSON.stringify(this.log_data)} | ` : message
// //let message = `${info.a},${info.a}`
return info.message
})
});
this.logger = logger
}
async info(message) {
this.logger.log('info', message);
}
async info(message, obj) {
this.logger.log('info', message, {
obj
})
}
}
class RegLogger {
constructor(outputfolder) {
try {
fs.rename(outputfolder+"/current_run_log.log", outputfolder+"/prev_run_log.log", (err) => {
// if (err) throw err;
console.log(`current run log file backed to ${outputfolder}/prev_run_log.log`);
});
} catch (err) {
console.log("run log fle rename error.May not exists yet")
}
const logger = winston.createLogger({
transports: [
new winston.transports.Console(),
new winston.transports.File({
filename: `${outputfolder}/run_log.log`
})
],
format: winston.format.printf((info) => {
let message = `${dateFormat()} | ${info.level.toUpperCase()} ${info.message} | `
message = info.obj ? message + `data:${JSON.stringify(info.obj)} | ` : message
// message = this.log_data ? message + `log_data:${JSON.stringify(this.log_data)} | ` : message
return message
})
});
this.logger = logger
}
async info(message) {
this.logger.log('info', message);
}
async info(message, obj) {
this.logger.log('info', message, {
obj
})
}
async debug(message) {
this.logger.log('debug', message);
}
async debug(message, obj) {
this.logger.log('debug', message, {
obj
})
}
async error(message) {
this.logger.log('error', message);
}
async error(message, obj) {
this.logger.log('error', message, {
obj
})
}
}
module.exports = {
CSVLogger: LoggerService,
RegLogger: RegLogger
}