# @blued-core/winston-logger

> 继承自 `logger-intl`，由 `winston-logger` 驱动。

Latest version **0.1.3** (published 2025-04-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install @blued-core/winston-logger
pnpm add @blued-core/winston-logger
yarn add @blued-core/winston-logger
bun add @blued-core/winston-logger
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2025-04-27 |
| First published | 2019-04-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 13.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | jiasm, ryli, nieweidong, fengcang2020, jarvan8888, chisecc |

## Links

- npm: https://www.npmjs.com/package/@blued-core/winston-logger
- npm.io page: https://npm.io/package/@blued-core/winston-logger

## Dependencies (5)

- [colors](https://npm.io/package/colors.md) ^1.3.3
- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [winston](https://npm.io/package/winston.md) ^3.3.3
- [@blued-core/logger-intl](https://npm.io/package/@blued-core/logger-intl.md) ^0.1.3
- [winston-daily-rotate-file](https://npm.io/package/winston-daily-rotate-file.md) ^4.5.5

## Recent versions

- 0.1.3 (latest) — 2025-04-27
- 0.1.2 — 2021-07-12
- 0.1.1 — 2021-05-28
- 0.1.0 — 2020-07-06
- 0.0.11 — 2019-12-24
- 0.0.10 — 2019-12-08
- 0.0.9 — 2019-05-18
- 0.0.8 — 2019-05-18
- 0.0.7 — 2019-04-23
- 0.0.6 — 2019-04-22
- 0.0.5 — 2019-04-22
- 0.0.4 — 2019-04-22
- 0.0.3 — 2019-04-22
- 0.0.1 — 2019-04-18

## README

## 一个较为公共的log组件封装

继承自 `logger-intl`，由 `winston-logger` 驱动。

```bash
npm i @blued-core/winston-logger
```

### 使用方法

```typescript
import Logger from '../../src/index'

const logger = new Logger('logs', 'test')
logger.access({ msg: 'test' })
logger.error(new Error('test error'), { msg: 'test' })
```

### constructor

Argument|Type|Required|Desc
:--|:--|:--|:--
`logPath`|`string`|✅|日志输出的路径
`logType`|`string`|✅|日志的标识符`YYYY-MM-DD-%logType%.<access|error>.log`
`isLocal`|`string`|❌|是否为本地环境，开启 terminal 输出，默认为`false`

### environment variables

Argument|Type|Required|Desc
:--|:--|:--|:--
`LOG_META_SERVICE`|`string`|❌|在日志 meta 里添加 service 字段，默认不添加
`LOG_CONSOLE`|`string`|❌|是否开启输出日志到 console，默认关闭。值为 `true` 时开启
`LOG_FILE`|`string`|❌|是否关闭输出日志到文件，默认开启。值为 `false` 时关闭输出到文件，LOG_FILE 前缀变量均失效
`LOG_FILE_DIRNAME`|`string`|❌|日志输出的文件夹路径，必须为绝对路径，会覆盖 `logPath` 的设置
`LOG_FILE_ACCESS_FILENAME`|`string`|❌|访问日志的文件名标识符，默认为 `%DATE%-${logType}.access.log`
`LOG_FILE_ERROR_FILENAME`|`string`|❌|错误日志的文件名标识符，默认为 `%DATE%-${logType}.error.log`
`LOG_FILE_DATE_PATTERN`|`string`|❌|日志文件的日期前缀格式，默认为 `YYYY-MM-DD`
`LOG_FILE_MAX_FILES`|`string`|❌|日志最长保存时间，默认 `30d` 30 天
`LOG_FILE_MAX_SIZE`|`string`|❌|日志文件的最大尺寸，默认为 `null`，不限制，可选择为 `1g` `100m`

### access

Argument|Type|Required|Desc
:--|:--|:--|:--
`data`|`Record<string, any>`|❌|日志的输出内容

### error

Argument|Type|Required|Desc
:--|:--|:--|:--
`error`|`Error`|✅|日志的输出内容
`data`|`Record<string, any>`|❌|日志的输出内容

---
_Source: https://npm.io/package/@blued-core/winston-logger · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
