在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:dominhhai/koa-log4js开源软件地址:https://github.com/dominhhai/koa-log4js开源编程语言:JavaScript 100.0%开源软件介绍:koa-log4jsA wrapper for log4js-node which support Koa logger middleware. Log message is forked from Express (Connect) logger file. NoteThis branch is use to Koa v2.x. To use Koa v0.x & v1.x, please check the master branch. Installationfor koa v0.x & v1.x
for koa v2.x
The default logger is for koa v2.x
UsageConfig koa-log4js is same as the original log4js-node. Normal log4js wayThis way is same as the original log4js-node. const log4js = require('koa-log4')
const log = log4js.getLogger('index')
log.info('index do some awesome things') Koa-middleware waySimilar to use Express (Connect) logger middleware. const log4js = require('koa-log4')
app.use(log4js.koaLogger(log4js.getLogger("http"), { level: 'auto' })) There are more configuration options: const log4js = require("koa-log4")
app.use(log4js.koaLogger(
// the logger to log to
log4js.getLogger("http"),
// the options object
{
// select the level all access logs will be set to, or use "auto" to choose depending on the status code (see next option)
level: "auto",
// if `level` is set to "auto" the default rule will map 200-299 to INFO, 300-399 to WARN and 400-599 to ERROR.
// you can override this behavior by setting your own custom levelMapper.
// (the example is the default implementation, do not copy unless you want to modify it)
levelMapper: function(statusCode) {
if (statusCode >= 400)
return levels.ERROR
if (statusCode >= 300)
return levels.WARN
return levels.INFO
}
}
)) Full ExampleCheck this repo for full example with OthersSee here for more info. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论