我正在尝试在 nodejs 项目(代码)中使用 winston.js 和 morgan 从消息属性中获取 originalURL:
winstone.je
const { createLogger, format, transports } = require('winston');
const { combine, timestamp, label, printf } = format;
const myFormat = printf(({ level, message, label, timestamp }) => {
return `${timestamp} ${level}: ${message}`;
});
const logger = createLogger({
format: combine(
label({ label: 'right meow!' }),
timestamp(),
myFormat
),
transports: [new transports.Console()]
});
应用程序.js
app.use(morgan('combined', { stream: winston.stream }));
的输出是:
2019-03-12T13:35:50.112Z : ::1 - - [12/Mar/2019:13:35:50 +0000] "GET /api/bar/origin/000a HTTP/1.1"
我正在寻找的是获得这部分:“GET /api/bar/origin/000a HTTP/1.1”,而不使用消息属性上的子字符串或切片,有没有办法从 myFormat const 获取 origineURL?