1.0.10 • Published 6 years ago
koa-log4js-logger v1.0.10
koa-log4js
Koa Log4js Middleware
Dependences
Installation
$ npm install koa-log4js-logger
Usage
const Koa = require('koa')
const logger = require('koa-log4js-logger')
const app = new Koa()
app.use(logger(app))
// response
app.use(ctx => {
ctx.log.info('Hello Koa')
ctx.body = 'Hello Koa';
})
if (!module.parent) {
const port = process.env.PORT || '3000'
app.listen(port)
app.log.info('Listening on ' + port)
}
Notes
Recommended that you .use() this middleware near the top to "wrap" all subsequent middleware.
Custom Production Configure
app.use(logger(app, {
access: { // access log
'type': 'dateFile',
'filename': 'logs/access.log',
'daysToKeep': 10,
'pattern': '.yyyy-MM-dd'
},
app: { // app log
'type': 'file',
'filename': 'logs/app.log',
'maxLogSize': 10485760,
'numBackups': 3,
},
error: { // error log
'type': 'file',
'filename': 'logs/errors.log',
}
}))