简体   繁体   English

登录生产最佳实践?

[英]Logging in production best practice?

Is it alright to use morgan as logger on production mode, or just throw it away and only use it on development mode? 是否可以在生产模式下使用morgan作为记录器,或者只是将其丢弃并仅在开发模式下使用它?
What's the best practice for logging on production mode? 登录生产模式的最佳做法是什么?

Yes! 是! It is all right to use Morgan as a logger on production mode. 将Morgan用作生产模式的记录器是可以的。

Arguably, if I can generalize to answer your question, the best practice in production is to log as many details as possible . 可以说,如果我可以概括地回答你的问题,那么生产中的最佳实践就是记录尽可能多的细节 The idea is that the logs on your server show you as much relevant information as you need. 我们的想法是,服务器上的日志会根据需要向您显示相关信息。 After all, you and the people with access to the server are the only one who sees them, right? 毕竟,您和访问服务器的人是唯一看到它们的人,对吧?

A strategy I use is a 'combined' mode in production, which is a bit more detailed, and a 'dev' mode in development, which is more concise. 我使用的策略是生产中的“组合”模式,它更加详细, 开发中“开发”模式更简洁。

You can switch those easily with environmental variable or whatever. 您可以使用环境变量或其他任何内容轻松切换。 Example: 例:

if (app.get('env') === 'production') {
  app.use(logger('combined'));
} else {
  app.use(logger('dev'));
}

Another thing I always configure is writing the logs in an external file . 我总是配置的另一件事是将日志写入外部文件 Needless to say why this is a nice to have, in production. 不用说为什么在生产中这是一件好事。

That's it in terms of Morgan. 这就是摩根。 If you are wondering about the best for logging in general, well, that's another question which is already answered . 如果你想知道一般的登录最好,那么这是另一个已经回答的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM