如何返回morgan组合格式字符串
async function sample(){
const res = await axios.get("http://localhost:3000/sample")
const morganFormattedString = morgan('combined', {stream: {write: res => res }})
}res 将是一个对象,我需要将res的对象转换为下面的字符串,这是由摩根内部完成的。
*ffff:127.0.0.1- 18/Jan/2019:04:59:10 +0000 "GET /sample HTTP/1.1“200 2 "http://localhost/”Mozilla/5.0 (linux) AppleWebKit/537.36 (KHTML,像壁虎一样) jsdom/11.12.0“
发布于 2019-01-18 09:20:15
morgan返回服务器端中间件,该中间件应该用于记录传入请求。您正在尝试使用它的客户端来记录传出请求,这不是它的目的。您想要完成的axios-debug-log应该可以工作,但是为了以combined格式记录请求,您必须使用自己配置它。
供参考,日志格式
morgan.format('combined', ':remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"')https://stackoverflow.com/questions/54248591
复制相似问题