Node.js Morgan日志记录中没有请求状态 [英] No Request Status in Node.js Morgan Logging

查看:145
本文介绍了Node.js Morgan日志记录中没有请求状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Azure VM上运行node.js应用程序(PM2处理负载平衡并重新启动).这是服务器设置和记录代码:

I'm running a node.js app on an Azure VM (with PM2 handling load balancing and restarting). Here's the server set up and logging code:

var logger = require('morgan');
var app = express();

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(flash());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', routes);
app.use('/api/v01', api.router);
app.use('/api/v02', apiv2.router);

在最后一天左右,我们开始连接到该网站时遇到很多麻烦.需要重新加载几次才能显示任何数据.

In the last day or so, we've started to have a lot of trouble connecting to the website. It takes a few reloads to get any data to show up.

我一直在浏览日志,试图找出问题所在.我没有看到任何错误,但是有很多这样的事例:

I've been looking through the logs trying to figure out what is up. I don't see any errors, but there are quite a few instances of this sort of thing:

WebApp-2 GET /portal - - ms - -
WebApp-3 GET /portal - - ms - -
WebApp-2 GET / - - ms - -
WebApp-2 GET / - - ms - -

这些似乎与无法查看页面的人一致.当一切正常时,日志看起来更像这样:

These seem to coincide with people being unable to view the pages. When things are working, the logs look more like this:

WebApp-3 GET / 302 16.532 ms - 58
WebApp-3 GET /portal 200 335.192 ms - 5239

格式为:method :url :status :response-time ms - :res[content-length] 根据Morgan文档.

我注意到的一件事是,当服务器不能真正工作时,日志记录中会用-字符代替状态,响应时间和内容长度.我习惯看到-的内容长度;这是服务器响应为304时发生的情况.尽管我从未见过-的响应时间或状态,尽管进行了搜索(包括Google以及此处的SO),但我不清楚这实际上意味着什么(在后台) .

One thing I've noticed is that when the server isn't really working, the logging has the - character in place of the status, response time, and content length. I'm used to seeing - for content-length; it's what happens when the server responds with a 304. I've never seen the - for response time or status though, Despite searching (both Google and here on SO) I'm unclear what this really means (under the hood).

有人知道这种缺乏身份意味着什么吗?如果它具有很好的含义,那么我是否犯了一个错误导致该错误?

Does anyone know what this lack of status means? If it has a well understood meaning, is there a mistake that I'm making that would lead to this?

推荐答案

根据问题报告此处GET / - - ms - -本质上意味着您永远不会在Node.js终止TCP连接以使其空闲时间过长之前发送响应".

According to the issue report here, GET / - - ms - - essentially means that "you never sent a response before Node.js killed the TCP connection for idling too long".

检查以确保向每个请求发送了响应.

Check to make sure that each request is sent a response.

这篇关于Node.js Morgan日志记录中没有请求状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆