Gathering detailed insights and metrics for koa2-winston
Gathering detailed insights and metrics for koa2-winston
Gathering detailed insights and metrics for koa2-winston
Gathering detailed insights and metrics for koa2-winston
npm install koa2-winston
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
37 Stars
258 Commits
7 Forks
1 Watchers
19 Branches
5 Contributors
Updated on Apr 28, 2025
Latest Version
3.2.1
Package Id
koa2-winston@3.2.1
Unpacked Size
50.86 kB
Size
11.20 kB
File Count
9
NPM Version
10.8.1
Node Version
22.4.1
Published on
Oct 24, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
koa2 version winston logger like express-winston
Add logger to your koa2 server in 3 lines
1npm i --save koa2-winston
1const { logger } = require('koa2-winston'); 2app.use(logger());
request log will look like
1{ 2 "req": { 3 "header": { 4 "host": "localhost:3000", 5 "connection": "keep-alive", 6 "upgrade-insecure-requests": "1", 7 "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36", 8 "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", 9 "dnt": "1", 10 "accept-encoding": "gzip, deflate, sdch, br", 11 "accept-language": "zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4,de;q=0.2,ja;q=0.2,it;q=0.2" 12 }, 13 "url": "/hello", 14 "method": "GET", 15 "href": "http://localhost:3000/hello", 16 "query": {} 17 }, 18 "started_at": 1494554053492, 19 "res": { 20 "header": { 21 "content-type": "application/json; charset=utf-8", 22 "content-length": "16" 23 }, 24 "status": 200 25 }, 26 "duration": 8, 27 "level": "info", 28 "message": "HTTP GET /hello" 29}
Each parameter has a default value, and you can customize your logger by changing the configuration
1app.use( 2 logger({ 3 transports: new winston.transports.Console({ json: true, stringify: true }), 4 level: 'info', 5 reqKeys: [ 6 'header', 7 'url', 8 'method', 9 'httpVersion', 10 'href', 11 'query', 12 'length', 13 ], 14 reqSelect: [], 15 reqUnselect: ['header.cookie'], 16 resKeys: ['header', 'status'], 17 resSelect: [], 18 resUnselect: [], 19 }) 20);
Many configuration explain can be found in logger
1app.use( 2 logger({ 3 reqKeys: [], 4 }) 5);
The req object will be empty
1{ 2 "req": {}, 3 "started_at": 1494486039864, 4 "res": { 5 "header": { 6 "content-type": "text/plain; charset=utf-8", 7 "content-length": "8" 8 }, 9 "status": 200 10 }, 11 "duration": 26, 12 "level": "info", 13 "message": "HTTP GET /" 14}
1app.use( 2 logger({ 3 resKeys: [], 4 }) 5);
The res object will be empty
1{ 2 "req": { 3 "header": { 4 "host": "127.0.0.1:59534", 5 "accept-encoding": "gzip, deflate", 6 "user-agent": "node-superagent/3.5.2", 7 "connection": "close" 8 }, 9 "url": "/", 10 "method": "GET", 11 "href": "http://127.0.0.1:59534/", 12 "query": {} 13 }, 14 "started_at": 1494486039864, 15 "res": {}, 16 "duration": 26, 17 "level": "info", 18 "message": "HTTP GET /" 19}
1app.use( 2 logger({ 3 reqUnselect: ['header.cookie', 'header.user-agent'], 4 }) 5);
The UA of request will be ignored
1{ 2 "req": { 3 "header": { 4 "host": "127.0.0.1:59534", 5 "accept-encoding": "gzip, deflate", 6 "connection": "close" 7 }, 8 "url": "/", 9 "method": "GET", 10 "href": "http://127.0.0.1:59534/", 11 "query": {} 12 }, 13 "started_at": 1494486039864, 14 "res": { 15 "header": { 16 "content-type": "text/plain; charset=utf-8", 17 "content-length": "8" 18 }, 19 "status": 200 20 }, 21 "duration": 26, 22 "level": "info", 23 "message": "HTTP GET /" 24}
1app.use( 2 logger({ 3 resSelect: ['body.success'], 4 }) 5);
The success
field on body
will be recorded
1{ 2 "req": { 3 "header": { 4 "host": "127.0.0.1:59534", 5 "accept-encoding": "gzip, deflate", 6 "connection": "close" 7 }, 8 "url": "/", 9 "method": "GET", 10 "href": "http://127.0.0.1:59534/", 11 "query": {} 12 }, 13 "started_at": 1494486039864, 14 "res": { 15 "header": { 16 "content-type": "text/plain; charset=utf-8", 17 "content-length": "8" 18 }, 19 "status": 200, 20 "body": { 21 // Any possible value given by the server 22 "success": false 23 } 24 }, 25 "duration": 26, 26 "level": "info", 27 "message": "HTTP GET /" 28}
At node 8.2
middleware x 90,281 ops/sec ±7.89% (13 runs sampled)
At node 8.4
middleware x 112,011 ops/sec ±10.26% (18 runs sampled)
With fast-json-stringify support, default transport logger is much faster
1total ops/sec { jsonstringify: 73544 } 2▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ 3total ops/sec { schemastringify: 90223 } 4▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
schemastringify
is 1.23x faster then jsonstringify
in this case
1total ops/sec { 'v1.7.1': 111416 } 2▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ 3total ops/sec { 'v2.4.0': 131234 } 4▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
v2.4.0
is 1.18x faster then v1.7.1
in this case
Related commit in HERE
JSPerf link in HERE
Testing in Chrome 70.0.3505 / Mac OS X 10.13.5
parseInt(401 / 100, 10) { 160,092,130 Ops/sec }
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
Math.floor(401 / 100) { 810,032,369 Ops/sec }
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
Math.floor
is 5.06x faster then parseInt
in this case
Finally, winston v3 support. But winston will install as dependencies not peerDependencies.
With better backward compatibility, users don't have to worry about the new version of koa2-winston will conflict with other winston usage in the project.
The fastest
koa2-winston ever. Nearly 3x
faster than previous versions.
1total ops/sec { 'v3.0.2': 180020 } 2▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ 3total ops/sec { 'v3.1.0': 541854 } 4▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
The above statistics come from
npm run bench
.
Biggest change
1- {req,res}.headers 2+ {req,res}.header
logger middleware for koa2 use winston
payload
object input arguments (optional, default {}
)
payload.transports
Array<object> customize transports (optional, default [newwinston.transports.Stream({stream:process.stdout})]
)payload.level
string default log level of logger (optional, default 'info'
)payload.reqKeys
string default request fields to be logged (optional, default ['header','url','method','httpVersion','href','query','length']
)payload.reqSelect
string additional request fields to be logged (optional, default []
)payload.reqUnselect
string request field will be removed from the log (optional, default ['header.cookie']
)payload.resKeys
string default response fields to be logged (optional, default ['header','status']
)payload.resSelect
string additional response fields to be logged (optional, default []
)payload.resUnselect
string response field will be removed from the log (optional, default []
)payload.logger
winston.transports.StreamTransportInstance? customize winston loggerpayload.msg
string customize log msg (optional, default HTTP%s%s
)1const { logger } = require('koa2-winston'); 2app.use(logger()); 3// request logger look like down here 4// { 5// "req": { 6// "header": { 7// "host": "127.0.0.1:59534", 8// "accept-encoding": "gzip, deflate", 9// "user-agent": "node-superagent/3.5.2", 10// "connection": "close" 11// }, 12// "url": "/", 13// "method": "GET", 14// "href": "http://127.0.0.1:59534/", 15// "query": {} 16// }, 17// "started_at": 1494486039864, 18// "res": { 19// "header": { 20// "content-type": "text/plain; charset=utf-8", 21// "content-length": "8" 22// }, 23// "status": 200 24// }, 25// "duration": 26, 26// "level": "info", 27// "message": "HTTP GET /" 28// }
Returns function logger middleware
path
stringschema
object generated json schemaType: Function
path
stringkeys
Array<string> schema keyshandler
schemaKeysHandlerFn assign pathlogger middleware for koa2 use winston
payload
object input arguments (optional, default {}
)
payload.reqKeys
Array<string> default request fields to be logged (optional, default ['header','url','method','httpVersion','href','query','length']
)payload.reqSelect
Array<string> additional request fields to be logged (optional, default []
)payload.reqUnselect
Array<string> request field will be removed from the log (optional, default ['header.cookie']
)payload.resKeys
Array<string> default response fields to be logged (optional, default ['header','status']
)payload.resSelect
Array<string> additional response fields to be logged (optional, default []
)payload.resUnselect
Array<string> response field will be removed from the log (optional, default []
)No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
Found 3/28 approved changesets -- score normalized to 1
Reason
9 existing vulnerabilities detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More