Logging requests to the App
Express comes with a built-in logging module called logger, it can be a very useful tool while you are developing the app. You enable it like any other Express module:
app.use(express.logger());
Without any options, the logger
middleware will log a detailed log. You can customize the details with the following tokens in the
format
option of the logger
middleware:
Token |
Content |
---|---|
|
The specific HTTP header of the request |
|
The specific HTTP header of the response |
|
The HTTP version |
|
How long it took to generate the response |
|
The user agent's IP address |
|
Date and time of request |
|
The HTTP method used for making the request |
|
The requested URL |
|
The URL that referred the current URL |
|
The user-agent signature |
|
The HTTP status |
And this is how you specify the log format using the tokens:
app.use(express.logger({ format: ':remote...