[英]How to get the OriginURL using morgan and winston.js format in nodejs?
我試圖在nodejs項目(代碼)中使用winston.js和morgan從message屬性獲取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()]
});
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?
好吧,根據Morgan文檔,您可以使用預定義的格式( combined
, tiny
,...)更改輸出格式,也可以自行創建類似於app.use(morgan(':method :url HTTP/:http-version', { stream: winston.stream }));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.