You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
978 B
36 lines
978 B
const winston = require('winston'); |
|
|
|
|
|
class LoggerUtil { |
|
logger; |
|
uuid; |
|
constructor(uuid) { |
|
this.uuid = uuid; |
|
this.logger = winston.createLogger({ |
|
level: 'info', |
|
format: winston.format.combine( |
|
winston.format.timestamp(), |
|
winston.format.json(), |
|
winston.format.printf(({timestamp, level, message}) => { |
|
if (uuid != null) { |
|
return `${timestamp} (traceId=${uuid}) [${level}]: ${message}`; |
|
} |
|
return `${timestamp} [${level}]: ${message}`; |
|
}) |
|
), |
|
transports: [ |
|
new winston.transports.Console(), // 控制台输出 |
|
// new winston.transports.File({filename: 'combined.log'}) // 文件输出 |
|
], |
|
}); |
|
} |
|
} |
|
|
|
module.exports = LoggerUtil |
|
|
|
|
|
// |
|
|
|
// let {logger} = new LoggerUtil('123123123'); |
|
// |
|
// logger.info('123')
|