# co-log

> Port of log4js work for node.RequestId is supported.

Latest version **2.1.8** (published 2025-02-01) · ISC license · 0 weekly downloads

## Install

```sh
npm install co-log
pnpm add co-log
yarn add co-log
bun add co-log
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.8 |
| Published | 2025-02-01 |
| First published | 2016-11-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 9.5 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | codeorg |
| Maintainers | codeorg |
| Keywords | log, log4js, koa, requestId |

## Links

- npm: https://www.npmjs.com/package/co-log
- npm.io page: https://npm.io/package/co-log

## Dependencies (2)

- [log4js](https://npm.io/package/log4js.md) ^3.0.6
- [co-util](https://npm.io/package/co-util.md) ^2.1.13

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 2.1.8 (latest) — 2025-02-01
- 2.1.7 — 2023-08-09
- 2.1.6 — 2022-12-05
- 2.1.5 — 2022-12-05
- 2.1.4 — 2022-12-05
- 2.1.3 — 2022-11-24
- 2.1.2 — 2022-11-24
- 2.1.1 — 2022-11-24
- 2.0.9 — 2022-11-24
- 2.0.8 — 2022-11-22
- 2.0.7 — 2022-09-10
- 2.0.6 — 2022-09-10
- 2.0.5 — 2022-09-09
- 2.0.4 — 2022-09-09
- 2.0.3 — 2022-09-09
- … 26 more at https://npm.io/package/co-log/versions

## README

# co-log
基于log4js的nodejs日志库，支持requestId输出，支持koa.
## Install
```git
npm i co-log
```
## Usage
```js
import {Log} from 'co-log';

let log = new Log({path: '/opt/yourpath'});
```
## Options
初始化参数
- `'path'` - `string`类型，日志存放路径
```js
const options= {
    path: '/opt/yourpath'
}
```

## RequestId设置
### `log.setRequestId(string)`
在function中设置requestId，所有`console.log`打印都带requestId
```js
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
```js
const Koa = require('koa')
const app = new Koa()
//第一个引入log的中间件
app.use(log.setRequestIdForKoa());
...
```

---
_Source: https://npm.io/package/co-log · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
