在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:ivpusic/koa-bunyan开源软件地址:https://github.com/ivpusic/koa-bunyan开源编程语言:JavaScript 100.0%开源软件介绍:koa-bunyanUsing node-bunyan as koa logging middleware Installation
Examplevar 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 NoteVersion >= 1.0.0 supports koa2, version < 1.0.0 supports koa1 LicenseMIT |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论