🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@nioh/logger

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nioh/logger

server logger which write file on disk

latest
npmnpm
Version
1.0.0
Version published
Weekly downloads
4
-42.86%
Maintainers
1
Weekly downloads
 
Created
Source

中间件: 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()

// 初始化 ELK 配置,/zkh/log/ 为固定目录,不可修改
const project = 'your-project-name'

app.use(elk({
  project,
  filename: env.LOCAL ? path.resolve(__dirname, '../log/logstash.log') : `/zkh/log/${project}/logstash.log`
}))

// debug, warn, error
app.use((ctx, next) => {
  
  // eg: 请求响应大于 300 ms, 可记录一条 Warning 日志
  ctx.elk.warn({
    message: 'slow response',
    type: 'api',
  })

  // eg: 当 catch 了某个错误,可记录一条 Error 日志
  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

Keywords

log

FAQs

Package last updated on 24 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts