node.js `morgan` 模块与快递应用程序有什么关系?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25468786/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does `morgan` module have to do with express apps?
提问by 3gwebtrain
In an express tutorial, the author was using the npm module morgan. What can morgan do for an express app? Could anyone help me understand this?
在一个快速教程中,作者使用了npm module morgan. 摩根能为快递应用做什么?谁能帮我理解这一点?
Got this by googling, but I do not understand anything here:
通过谷歌搜索得到了这个,但我在这里什么都不明白:
var express = require('express')
var morgan = require('morgan')
var app = express()
app.use(morgan('combined'))
morgan('combined')
morgan(':remote-addr :method :url')
morgan(function (tokens, req, res) {
return req.method + ' ' + req.url
})
回答by Peter Lyons
Morgan is used for logging request details. However, the snippet in your question doesn't make sense because it's not actually a single coherent snippet top to bottom. It is a series of examples of the various types of options you can pass to morgan. In a real program, you would only need one of them. For example:
Morgan 用于记录请求详细信息。但是,您问题中的代码段没有意义,因为它实际上不是从上到下的单个连贯代码段。它是您可以传递给摩根的各种类型期权的一系列示例。在实际程序中,您只需要其中之一。例如:
var express = require('express')
var morgan = require('morgan')
var app = express()
//This tells express to log via morgan
//and morgan to log in the "combined" pre-defined format
app.use(morgan('combined'))
//That's it. Everything in your snippet after this are just
//other variations your might want to use
回答by Krishna Ganeriwal
Morgan is basically a logger, on any requests being made,it generates logs automatically.
Morgan 基本上是一个记录器,在发出任何请求时,它都会自动生成日志。
回答by Ravi Malviya
Morgan is a popular HTTP request middleware logger for Node.js and basically used as a logger. It can be used with node js' winston package to consolidate HTTP request data logs with other information.
Morgan 是 Node.js 的流行 HTTP 请求中间件记录器,基本上用作记录器。它可以与 node js 的 winston 包一起使用,将 HTTP 请求数据日志与其他信息合并。
回答by Elle Kiumarsian
Morgan:is another HTTP request logger middleware for Node.js. It simplifies the process of logging requests to your application. You might think of Morgan as a helper that collects logs from your server, such as your request logs. It saves developers time because they don't have to manually create common logs. It standardizes and automatically creates request logs.
Morgan:是另一个用于 Node.js 的 HTTP 请求记录器中间件。它简化了将请求记录到应用程序的过程。您可能会将 Morgan 视为从您的服务器收集日志(例如您的请求日志)的助手。它节省了开发人员的时间,因为他们不必手动创建公共日志。它标准化并自动创建请求日志。
Morgan can operate standalone, but commonly it's used in combination with Winston. Winston is able to transport logs to an external location, or query them when analyzing a problem.
Morgan 可以独立运行,但通常与 Winston 结合使用。Winston 能够将日志传输到外部位置,或在分析问题时查询它们。

