Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
express-req-logger
Advanced tools
Readme
HTTP request logger middleware for Express.
npm i -S express-req-logger
const express = require('express');
const logger = require('express-req-logger');
var app = express();
app.use(logger());
// GET / HTTP/1.1 200 367ms
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
HTTP request method. GET
Request path. /index.html
HTTP version number. 1.1
Request status code. 200
Request to respond to the duration of the unit, in milliseconds. 263ms
Remote client IP address. ::ffff:192.168.0.100
Current date. 2017-05-14
Current time. 19:00:00
Current week. 周日
Remote client user agent content.
const logger = require('express-req-logger');
var app = require('express')();
app.use(logger(
'[:date :time] :method :url HTTP/:httpVersion :status'
));
// [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.use(logger(
'[:date :when :time] :method :url'
), {
// Add the new when field and add it to the format parameter.
when: function (req, res) { // Can receive request and response object.
return (new Date().getHours() >= 12) ? 'PM' : 'AM';
},
// Rewrite the method function
method: function (req, res) {
return req.method.toLowerCase();
}
});
// [2017-05-14 上午 10:22:29] get /index.html
Express的HTTP请求日志中间件
npm i -S express-req-logger
const express = require('express');
const logger = require('express-req-logger');
var app = express();
app.use(logger());
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
HTTP请求方法。GET
请求路径。/index.html
HTTP版本。1.1
请求状态码。200
请求到响应持续的时间,单位为毫秒。263ms
客户端IP地址。::ffff:192.168.0.100
当前日期。2017-05-14
,本项目首次提交时间。
当前时间。19:00:00
当前星期。周日
客户端用户代理内容。
const logger = require('express-req-logger');
var app = require('express')();
app.use(logger(
'[:date :time] :method :url HTTP/:httpVersion :status'
));
// [2017-05-14 19:23:33] GET /index.html HTTP/1.1 200
option
用于修改字段的输出,或增加字段。
app.use(logger(
'[:date :when :time] :method :url'
), {
// 自己增加新的when字段,并加入到format参数中。
when: function (req, res) { // 可接收到request和response对象。
return (new Date().getHours() >= 12) ? '下午' : '上午';
},
// 重写method方法
method: function (req, res) {
return req.method.toLowerCase();
}
});
// [2017-05-14 上午 10:22:29] get /index.html
FAQs
HTTP request logger middleware for Express.
The npm package express-req-logger receives a total of 7 weekly downloads. As such, express-req-logger popularity was classified as not popular.
We found that express-req-logger demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.