sword-logger
v1.0.4
Published
logger middleware for sword system
Downloads
7
Readme
sword-logger
logger middleware for sword system
Installation
$ npm install --save sword-logger
Usage
var koa = require('koa')
var swordLogger = require('sword-logger');
koa.use(swordLogger(opts))
log file eg, sword-logger-2016-9-26.log
,
log file content eg,
{"name":"sword-logger-2016-9-26","hostname":"Gejiawen.local","pid":71410,"level":30,"category":"template","req_id":"06b0bb2e-72dd-449e-b693-cef8738bdd85","label":"start","msg":"POST localhost:8000/user","time":"2016-09-26T10:32:08.472Z","v":0}
{"name":"sword-logger-2016-9-26","hostname":"Gejiawen.local","pid":71410,"level":30,"category":"template","req_id":"06b0bb2e-72dd-449e-b693-cef8738bdd85","label":"finished","status":200,"duration":1,"msg":"POST localhost:8000/user 200 1ms","time":"2016-09-26T10:32:08.473Z","v":0}
extra field as follows,
category
req_id
label
duration
template
request
response
Configuration
opts
default value as follows,
{
"logFolder": "./logs",
"logFilePrefix": "sword-logger",
"logFileSuffix": ".log",
"logRecordName": "sword-logger-yyyy-m-dd",
"enableLogSrc": false,
"enableSaveInterval": false,
"logSaveInterval": 6e4,
"enableSaveBuffer": false,
"logSaveBuffer": 100,
"enableReqTimeoutLimit": false,
"reqTimeoutLimit": 1e3,
"enableRequestDetail": false,
"enableResponseDetail": false,
"enableTemplateDetail": false
}
logFolder
, log folderlogFilePrefix
, log file prefixlogFileSuffix
, log file suffixlogRecordName
, logger instance nameenableLogSrc
, enable log src and line number or notenableSaveInterval
, enable write to log file by interval or notlogSaveInterval
, interval time, default is 60000msenableSaveBuffer
, enable write to log file by buffer or notlogSaveBuffer
, buffer records number, default is 100enableReqTimeoutLimit
, enable request timeout limit or notreqTimeoutLimit
, request timeout limit, default is 1000ms, sword-logger useWARN
level when over request timeout limitenableRequestDetail
, enable request log detail or notenableResponseDetail
, enable response log detail or notenableTemplateDetail
, enable template render log or not
License
MIT © gejiawen