• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ivpusic/koa-bunyan: Using node-bunyan as koa logging middleware

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

ivpusic/koa-bunyan

开源软件地址:

https://github.com/ivpusic/koa-bunyan

开源编程语言:

JavaScript 100.0%

开源软件介绍:

koa-bunyan

Using node-bunyan as koa logging middleware

Installation

npm install koa-bunyan

Example

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
}));
// 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

Note

Version >= 1.0.0 supports koa2, version < 1.0.0 supports koa1

License

MIT




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap