co-log
v2.1.7
Published
Port of log4js work for node.RequestId is supported.
Downloads
17
Readme
co-log
基于log4js的nodejs日志库,支持requestId输出,支持koa.
Install
npm i co-log
Usage
import {Log} from 'co-log';
let log = new Log({path: '/opt/yourpath'});
Options
初始化参数
'path'
-string
类型,日志存放路径
const options= {
path: '/opt/yourpath'
}
RequestId设置
log.setRequestId(string)
在function中设置requestId,所有console.log
打印都带requestId
async function test() {
log.setRequestId('ae21f206375744f0b6188f45b7f856d3')
console.log({a:1})
//[2022-11-24 23:18:47.160] [INFO] - ae21f206375744f0b6188f45b7f856d3 {a:1}
}
log.setRequestIdForKoa()
返回koa框架的中间件,所有api请求都自带requestId
const Koa = require('koa')
const app = new Koa()
//第一个引入log的中间件
app.use(log.setRequestIdForKoa());
...