在这篇文章之后:Node.js - 记录/使用 morgan 和 winston
我将记录器设置如下;
const winston = require('winston');
const datadogWinston = require('datadog-winston');
const os = require('os');
const logger = winston.createLogger({
level: 'info',
format: winston.format.simple(),
transports: [
new winston.transports.Console(),
new winston.transports.File({filename: 'test.log'}),
new datadogWinston({
apiKey: process.env.DATADOG_APIKEY,
hostname: os.hostname(),
service: 'korabo',
ddsource: 'nodejs',
}),
],
});
logger.stream = {
write: (message, _encoding) => {
logger.info(message);
},
};
module.exports = logger;
然而,每当winston 记录一个项目时,它最终看起来像这样;
info: [0mGET /stylesheets/style.css [36m304[0m 1.550 ms - -[0m
摩根实例;
const logger = require('./lib/logger');
const app = express();
...
app.use(morgan('dev', {stream: logger.stream}));
我怎样才能修复那些奇怪的字符出现在日志中?