co-log
TypeScript icon, indicating that this package has built-in type declarations

2.1.7 • Public • Published

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());
...

Readme

Keywords

Package Sidebar

Install

npm i co-log

Weekly Downloads

1

Version

2.1.7

License

ISC

Unpacked Size

9.13 kB

Total Files

10

Last publish

Collaborators

  • codeorg