Socket
Book a DemoInstallSign in
Socket

co-log

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

co-log

Port of log4js work for node.RequestId is supported.

2.1.8
latest
npmnpm
Version published
Maintainers
1
Created
Source

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

Keywords

log

FAQs

Package last updated on 01 Feb 2025

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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.