我正在尝试在nodejs项目(代码)中使用winston.js和morgan从message属性获取原始URL:
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()]
});
app.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”,而不在message属性上使用子字符串或切片,是否有办法从myFormat const获取origineURL请吗?