blob: c636681c6ee74d1e5ccb81572edbff3abc251d36 (
plain)
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
|
const winston = require('winston')
const chalk = require('chalk')
class Logger {
constructor(x) {
this.logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
defaultMeta: {service: 'user-service'},
transports: [
new winston.transports.File({filename: 'error.log', level: 'error'}),
new winston.transports.File({filename: 'combined.log'})
]
})
//if (process.env.NODE_ENV !== 'prod') {this.logger.add(new winston.transports.Console({format: winston.format.simple()}))}
}
Error(x) {
if (process.env.NODE_ENV !== 'prod') {
//console.error(chalk.red(x))
console.error(x)
} else {
this.logger.error(x)
}
}
Info(x) {
if (process.env.NODE_ENV !== 'prod') {
//console.log(chalk.yellow(x))
console.log(x)
} else {
this.logger.info(x)
}
}
}
module.exports = (x) => {return new Logger(x)}
|