中间件: elk
安装
Install with npm
npm i @server/elk --registry=http://npm.zkh360.com
说明
日志中间件,elk
使用
import * as path from 'path'
import * as Koa from 'koa'
import * as env from '@server/env'
import elk from '@server/elk'
const app = new Koa()
const project = 'your-project-name'
app.use(elk({
project,
filename: env.LOCAL ? path.resolve(__dirname, '../log/logstash.log') : `/zkh/log/${project}/logstash.log`
}))
app.use((ctx, next) => {
ctx.elk.warn({
message: 'slow response',
type: 'api',
})
ctx.elk.error({
message: err.message,
type: 'api',
})
await next()
})
app.listen(3000)
日志:log example
app.on('error', (err, ctx) => {
debug('APP ERROR: ', ctx)
ctx && ctx.elk && ctx.elk.error({
message: err.message,
type: 'app'
})
})
ChangeLog
Tests
npm test
License
2019@ZKH-FE