Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ivpusic/koa-bunyan
Using node-bunyan as koa logging middleware
https://github.com/ivpusic/koa-bunyan
Last synced: 2 months ago
JSON representation
Using node-bunyan as koa logging middleware
- Host: GitHub
- URL: https://github.com/ivpusic/koa-bunyan
- Owner: ivpusic
- Created: 2014-05-23T18:02:56.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-11-13T12:59:50.000Z (about 6 years ago)
- Last Synced: 2024-10-31T08:52:20.703Z (2 months ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 22
- Watchers: 3
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-koa - koa-bunyan - 使用node-bunyan的中间件。 ![](https://img.shields.io/github/stars/ivpusic/koa-bunyan.svg?style=social&label=Star) ![](https://img.shields.io/npm/dm/koa-bunyan.svg?style=flat-square) (仓库 / 中间件)
README
koa-bunyan
==========Using node-bunyan as koa logging middleware
# Installation
```
npm install koa-bunyan
```## Example
```Javascript
var koaLogger = require('koa-bunyan');var koa = require('koa');
var app = koa();var bunyan = require('bunyan');
// setup you logger instance
var logger = bunyan.createLogger({name: "myapp"});app.use(koaLogger(logger, {
// which level you want to use for logging?
// default is info
level: 'debug',
// this is optional. Here you can provide request time in ms,
// and all requests longer than specified time will have level 'warn'
timeLimit: 100,
headers: ['Accept']
// optional - provide a list of request headers you'd like to log
}));
``````bash
// then start server
// let we say... node app.js | ./node_modules/bunyan/bin/bunyan -o short// result
22:36:34.043Z WARN myapp: [RES] GET /api/products?top=5 (200) took 610 ms
22:36:34.172Z INFO myapp: [REQ] GET /api/categories/535c4375bcbcc794660b6c1d headers {"Accept": "*/*"}
22:36:34.184Z INFO myapp: [RES] GET /api/categories/535c4375bcbcc794660b6c1d (200) took 12 ms
22:36:34.375Z INFO myapp: [REQ] GET /Screenshot%20from%202014-03-15%2011:17:20.png
22:36:34.378Z INFO myapp: [REQ] GET /51a2035604cea64219.jpg
22:36:34.381Z INFO myapp: [REQ] GET /matrix.jpg
22:36:34.394Z INFO myapp: [REQ] GET /fonts/fontawesome-webfont.woff?v=4.1.0
22:36:34.400Z INFO myapp: [RES] GET /Screenshot%20from%202014-03-15%2011:17:20.png (200) took 26 ms
22:36:34.406Z INFO myapp: [RES] GET /fonts/fontawesome-webfont.woff?v=4.1.0 (200) took 12 ms
22:36:34.415Z INFO myapp: [RES] GET /51a2035604cea64219.jpg (200) took 38 ms
22:36:34.417Z INFO myapp: [RES] GET /matrix.jpg (200) took 36 ms
```Logs also can go to somewhere else. It depends on you passed logger configuration.
For more details how to configure bunyan look at [node-bunyan](https://github.com/trentm/node-bunyan)## Note
Version >= 1.0.0 supports koa2, version < 1.0.0 supports koa1
# License
**MIT**