express-req-logger
HTTP request logger middleware for Express.
usage
npm i -S express-req-logger
const express = ;const logger = ; var app = ; app; // GET / HTTP/1.1 200 367ms
API
logger(format, option)
The format
argument is a string, either 'tiny'
,'normal'
, 'long'
, or something like that ':method :url HTTP/:httpVersion :status :duration'
.
format
normal Default style.
GET / HTTP/1.1 200 218ms
tiny Short style.
GET / 200
long Long style.
[2017-05-14 21:03:25 周日] ::ffff:192.168.0.100 /index.html HTTP/1.1 304 23ms Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebkit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
:method
HTTP request method. GET
:url
Request path. /index.html
:httpVersion
HTTP version number. 1.1
:status
Request status code. 200
:duration
Request to respond to the duration of the unit, in milliseconds. 263ms
:ip
Remote client IP address. ::ffff:192.168.0.100
:date
Current date. 2017-05-14
:time
Current time. 19:00:00
:day
Current week. 周日
:userAgent
Remote client user agent content.
const logger = ;var app = ; app; // [2017-05-14 19:23:33] GET /index.html HTTP/1.1 200
option
Used to modify the output of a field, or to add a field.
app; // [2017-05-14 上午 10:22:29] get /index.html
express-req-logger
Express的HTTP请求日志中间件
使用方法
npm i -S express-req-logger
const express = ;const logger = ; var app = ; app;
接口
logger(format, option)
format
参数是一个字符串,可以是预设的配置'tiny'
、'normal'
、'long'
或者是类似':method :url HTTP/:httpVersion :status :duration'
。
format
normal 默认风格。如下所示
GET / HTTP/1.1 200 218ms
tiny 简短风格
GET / 200
long 长风格
[2017-05-14 21:03:25 周日] ::ffff:192.168.0.100 /index.html HTTP/1.1 304 23ms Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebkit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
:method
HTTP请求方法。GET
:url
请求路径。/index.html
:httpVersion
HTTP版本。1.1
:status
请求状态码。200
:duration
请求到响应持续的时间,单位为毫秒。263ms
:ip
客户端IP地址。::ffff:192.168.0.100
:date
当前日期。2017-05-14
,本项目首次提交时间。
:time
当前时间。19:00:00
:day
当前星期。周日
:userAgent
客户端用户代理内容。
const logger = ;var app = ; app; // [2017-05-14 19:23:33] GET /index.html HTTP/1.1 200
option
用于修改字段的输出,或增加字段。
app; // [2017-05-14 上午 10:22:29] get /index.html