wm_logger
v1.0.4
Published
wm logger module
Downloads
1
Readme
wm_logger module
koa-skeleton 日志记录中间件,基于bunyan
Install
npm install wm_logger --save
Usage
const logger = require('wm_logger')({ name: 'appName', filterParameters: ['password']})
// 中间件
app.use(logger.requestLogger)
// 普通使用
logger.info({type: "logic"}, "hello")
ctx.requestId 可以获取请求 id 的值
Feature
- JSON 风格存储
- 自动记录请求日志中间件
- 自动添加请求链唯一标识 requestId(存储在 headers 的 HTTP-X-REQUEST-ID 键上面)
- 日志类型 type 的值有 request/response/logic 等
- 过滤请求字段 filterParameters,默认值 [password]
Request logger example
// request
{"name":"wm_user","hostname":"linqingrongdeMacBook-Air.local","pid":28845,"level":30,"type":"request","requestId":"200c4330-2f16-11e7-a471-011e17f971de","time":"2017-05-02 17:02:53","url":"/api/v1/users/58f9e0e80cd4f74e28c435fc","method":"GET","protocol":"http","headers":{"host":"localhost:3001","connection":"keep-alive","user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36","cache-control":"no-cache","authorization":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjoiNThmMGE4YWRiMjliMmUxOTFmNzJkNmY0IiwiaWF0IjoxNDkyMTY2ODI5fQ.lbrgJVn7KMMczCaxQsuRsKjqnOKQXpRet9Cp3xJfVWY","accept":"*/*","accept-encoding":"gzip, deflate, sdch, br","accept-language":"zh-CN,zh;q=0.8,en;q=0.6","cookie":"Hm_lvt_e1c504a909fb6814523e69845ace2c87=1468599115; _zg=%7B%22uuid%22%3A%20%22155ef600f5c0-086cb0fc275b88-37607b02-1fa400-155ef600f5ec1%22%2C%22sid%22%3A%201468599897.955%2C%22updated%22%3A%201468602263.529%2C%22info%22%3A%201468599897964%7D"},"msg":"","v":0}
// response
{"name":"wm_user","hostname":"linqingrongdeMacBook-Air.local","pid":28845,"level":30,"type":"response","requestId":"200c4330-2f16-11e7-a471-011e17f971de","method":"GET","url":"/api/v1/users/58f9e0e80cd4f74e28c435fc","status":200,"time":"2017-05-02 17:02:53","responseTime":"10ms","msg":"","v":0}
TODO
- add test