@done-coding/output-node 0.1.0-alpha.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,22 +1,27 @@
1
1
  # @done-coding/output-node
2
2
 
3
+ [![NPM Version](https://img.shields.io/npm/v/@done-coding/output-node)](https://www.npmjs.com/package/@done-coding/output-node)
4
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
5
+ [![Codecov](https://img.shields.io/codecov/c/github/done-coding/output-node)](https://codecov.io/gh/done-coding/output-node)
6
+
3
7
  Node.js 环境下的同构输出工具包,基于 @done-coding/output-core 核心包构建,提供控制台输出和日志文件输出功能。
4
8
 
5
- ## 特性
9
+ ## 功能特性
6
10
 
7
11
  - 🎨 **丰富的控制台输出** - 支持多种输出类型和颜色配置
8
12
  - 📝 **专业的日志文件输出** - 基于 pino 的高性能日志记录
9
13
  - 🔄 **混合类型接口** - 支持函数调用和属性链式调用两种方式
10
14
  - 🛡️ **临终落盘保护** - 使用 signal-exit 库实现非侵入式进程退出监听
11
- - 🚨 **信号监听** - 与 NestJS 等现代框架完美兼容
12
- - ⚡ **高性能** - 异步日志写入,预计算枚举映射
15
+ - 🚨 **框架兼容** - 与 NestJS 等现代框架的关闭钩子完美兼容
16
+ - ⚡ **高性能** - 异步日志写入,可配置缓冲区大小
13
17
  - 🔧 **完整的错误处理** - 输入验证、配置验证、文件权限检查
14
- - 📦 **TypeScript 支持** - 完整的类型定义和类型推导
18
+ - 📦 **完整类型支持** - 100% TypeScript 类型定义和类型推导
15
19
  - 🎯 **输出模式切换** - 支持控制台和日志文件之间的智能切换
16
20
  - 📋 **TABLE 类型特殊处理** - 智能表格数据展示和 JSON 序列化
17
- - 🔧 **常量集中管理** - 所有配置参数的默认值统一管理
18
21
 
19
- ## 安装
22
+ ## 快速开始
23
+
24
+ ### 安装
20
25
 
21
26
  ```bash
22
27
  npm install @done-coding/output-node
@@ -26,247 +31,182 @@ yarn add @done-coding/output-node
26
31
  pnpm add @done-coding/output-node
27
32
  ```
28
33
 
29
- ## 快速开始
30
-
31
- ### 控制台输出
34
+ ### 最小可用示例
32
35
 
33
36
  ```typescript
34
37
  import {
35
38
  createOutputConsole,
36
- OutputConsoleTypeEnum,
37
- } from "@done-coding/output-node";
38
-
39
- // 创建控制台输出实例
40
- const outputConsole = createOutputConsole({
41
- enableColor: true, // 启用颜色输出
42
- silent: false, // 非静默模式
43
- });
44
-
45
- // 函数调用方式
46
- outputConsole(OutputConsoleTypeEnum.INFO, "这是一条信息");
47
- outputConsole(OutputConsoleTypeEnum.SUCCESS, "操作成功!");
48
- outputConsole(OutputConsoleTypeEnum.ERROR, "发生错误");
49
-
50
- // 属性链式调用方式(推荐)
51
- outputConsole.info("这是一条信息");
52
- outputConsole.success("操作成功!");
53
- outputConsole.error("发生错误");
54
- outputConsole.warn("这是一个警告");
55
- outputConsole.debug("调试信息");
56
- outputConsole.stage("当前步骤");
57
- outputConsole.skip("跳过此步骤");
58
-
59
- // TABLE 类型特殊处理
60
- outputConsole.table({
61
- name: "张三",
62
- age: 25,
63
- city: "北京",
64
- });
65
- ```
66
-
67
- ### 日志文件输出
68
-
69
- ```typescript
70
- import {
71
39
  createOutputLogFile,
72
- OutputLogFileTypeEnum,
73
40
  } from "@done-coding/output-node";
74
41
 
75
- // 创建日志文件输出实例
76
- const logger = createOutputLogFile({
77
- logFilePath: "app.log", // 可选,默认自动生成
78
- prettyPrint: false, // 是否美化输出
79
- silent: false, // 非静默模式
80
- sync: false, // 异步写入(推荐)
81
- bufferSize: 4096, // 缓冲区大小
82
- });
83
-
84
- // 函数调用方式
85
- logger(OutputLogFileTypeEnum.INFO, "应用启动");
86
- logger(OutputLogFileTypeEnum.ERROR, "数据库连接失败");
42
+ // 创建控制台输出
43
+ const output = createOutputConsole();
44
+ output.info("Hello World");
45
+ output.success("操作成功");
87
46
 
88
- // 属性链式调用方式(推荐)
47
+ // 创建日志文件输出
48
+ const logger = createOutputLogFile({ logFilePath: "app.log" });
89
49
  logger.info("应用启动");
90
- logger.warn("内存使用率较高");
91
- logger.error("数据库连接失败");
92
- logger.debug("调试信息");
93
- logger.trace("详细跟踪信息");
94
- logger.fatal("致命错误,应用即将退出");
50
+ logger.error("发生错误");
95
51
  ```
96
52
 
97
- ### 输出模式切换
53
+ ## 架构设计
98
54
 
99
- ```typescript
100
- import { outputLogFile } from "@done-coding/output-node";
101
-
102
- // 支持输出到控制台
103
- const logger1 = outputLogFile({
104
- outputToConsole: true, // 输出到控制台
105
- prettyPrint: true, // 美化输出
106
- });
55
+ ### 分层架构
107
56
 
108
- // 支持输出到文件
109
- const logger2 = outputLogFile({
110
- outputToConsole: false, // 输出到文件
111
- logFilePath: "app.log",
112
- sync: true, // 同步写入
113
- });
57
+ ```
58
+ ┌─────────────────────────────────────┐
59
+ │ Node.js 适配包层 │
60
+ │ (@done-coding/output-node) │
61
+ ├─────────────────────────────────────┤
62
+ │ 核心包层 │
63
+ │ (@done-coding/output-core) │
64
+ ├─────────────────────────────────────┤
65
+ │ 驱动实现层 │
66
+ │ (console.log, pino, chalk, etc.) │
67
+ └─────────────────────────────────────┘
114
68
  ```
115
69
 
116
- ### 切换和同步逻辑
117
-
118
- ```typescript
119
- import {
120
- createOutputConsole,
121
- createOutputLogFile,
122
- OutputConsoleTypeEnum,
123
- } from "@done-coding/output-node";
124
-
125
- // 创建日志文件输出实例
126
- const fileLogger = createOutputLogFile({ logFilePath: "error.log" });
127
-
128
- // 创建带有切换和同步逻辑的控制台输出
129
- const outputConsole = createOutputConsole({
130
- enableColor: true,
131
- // 错误级别切换到日志文件(不在控制台显示)
132
- isSwitchLogFile: (type) => type === OutputConsoleTypeEnum.ERROR,
133
- // 警告级别同步到日志文件(控制台和文件都显示)
134
- isSyncToLogFile: (type) => type === OutputConsoleTypeEnum.WARN,
135
- // 指定日志文件输出函数
136
- outputFileFn: fileLogger,
137
- });
70
+ ### 设计原则
138
71
 
139
- outputConsole.info("普通信息"); // 只在控制台显示
140
- outputConsole.warn("警告信息"); // 控制台和文件都显示
141
- outputConsole.error("错误信息"); // 只在文件中记录
142
- ```
72
+ 1. **自动化驱动** - 自动创建和管理输出驱动实现
73
+ 2. **零配置** - 提供合理的默认配置,开箱即用
74
+ 3. **高性能** - 异步日志写入,可配置缓冲区
75
+ 4. **安全可靠** - 完整的错误处理和防御性编程
76
+ 5. **框架兼容** - 与现代框架(NestJS、Express 等)完美兼容
77
+ 6. **极简 API** - 最少化的配置参数,易于使用
143
78
 
144
79
  ## API 文档
145
80
 
146
- ### createOutputConsole(options?)
81
+ ### createOutputConsole
147
82
 
148
83
  创建控制台输出实例。
149
84
 
150
- #### 参数
85
+ **签名:**
151
86
 
152
- - `options` (可选) - 配置选项
153
- - `silent?: boolean` - 是否静默模式,默认 `false`
154
- - `enableColor?: boolean` - 是否启用颜色输出,默认 `true`
155
- - `colorMap?: Record<OutputConsoleTypeEnum, string>` - 自定义颜色映射
156
- - `isSwitchLogFile?: (type: OutputConsoleTypeEnum) => boolean` - 切换到日志文件的条件函数
157
- - `isSyncToLogFile?: (type: OutputConsoleTypeEnum) => boolean` - 同步到日志文件的条件函数
158
- - `outputFileFn?: OutputLogFile` - 日志文件输出函数
159
-
160
- #### 返回值
161
-
162
- 返回 `OutputConsole` 混合类型实例,支持:
87
+ ```typescript
88
+ function createOutputConsole(
89
+ options?: CreateOutputConsoleOptions,
90
+ ): OutputConsole;
91
+ ```
163
92
 
164
- - 函数调用:`output(type, ...messages)`
165
- - 属性调用:`output.info(...messages)`、`output.error(...messages)` 等
93
+ **参数:**
166
94
 
167
- ### createOutputLogFile(options?)
95
+ | 参数 | 类型 | 默认值 | 说明 |
96
+ | ----------------------- | ------------------------------------- | ------ | -------------------- |
97
+ | options.silent | boolean | false | 是否静默模式 |
98
+ | options.enableColor | boolean | true | 是否启用颜色输出 |
99
+ | options.colorMap | Record<OutputConsoleTypeEnum, string> | - | 自定义颜色映射 |
100
+ | options.isSwitchLogFile | (type) => boolean | - | 切换到日志文件的条件 |
101
+ | options.isSyncToLogFile | (type) => boolean | - | 同步到日志文件的条件 |
102
+ | options.outputFileFn | OutputLogFile | - | 日志文件输出函数 |
168
103
 
169
- 创建日志文件输出实例。
104
+ **返回值:** OutputConsole 混合类型实例
170
105
 
171
- #### 参数
106
+ **示例:**
172
107
 
173
- - `options` (可选) - 配置选项
174
- - `silent?: boolean` - 是否静默模式,默认 `false`
175
- - `logFilePath?: string` - 日志文件路径,默认自动生成
176
- - `prettyPrint?: boolean` - 是否启用美化输出,默认 `false`
177
- - `sync?: boolean` - 是否同步写入,默认 `false`
178
- - `bufferSize?: number` - 缓冲区大小,默认 `4096`
179
-
180
- #### 返回值
108
+ ```typescript
109
+ const output = createOutputConsole({
110
+ enableColor: true,
111
+ silent: false,
112
+ });
181
113
 
182
- 返回 `OutputLogFile` 混合类型实例,支持:
114
+ output.info("信息");
115
+ output.success("成功");
116
+ output.error("错误");
117
+ ```
183
118
 
184
- - 函数调用:`logger(type, ...messages)`
185
- - 属性调用:`logger.info(...messages)`、`logger.error(...messages)` 等
119
+ ### createOutputLogFile
186
120
 
187
- ### outputLogFile(options?)
121
+ 创建日志文件输出实例。
188
122
 
189
- 创建支持输出模式切换的日志实例。
123
+ **签名:**
190
124
 
191
- #### 参数
125
+ ```typescript
126
+ function createOutputLogFile(
127
+ options: CreateOutputLogFileOptions,
128
+ ): OutputLogFile;
129
+ ```
192
130
 
193
- - `options` (可选) - 配置选项
194
- - `outputToConsole?: boolean` - 是否输出到控制台,默认 `false`
195
- - `prettyPrint?: boolean` - 是否美化输出,默认 `false`
196
- - `logFilePath?: string` - 日志文件路径(当 `outputToConsole` 为 `false` 时)
197
- - `sync?: boolean` - 是否同步写入,默认 `false`
198
- - `bufferSize?: number` - 缓冲区大小,默认 `4096`
131
+ **参数:**
199
132
 
200
- ### 输出类型枚举
133
+ | 参数 | 类型 | 默认值 | 说明 |
134
+ | ----------------------- | ----------------- | ------ | -------------------- |
135
+ | options.logFilePath | string | - | 日志文件路径(必传) |
136
+ | options.silent | boolean | false | 是否静默模式 |
137
+ | options.sync | boolean | false | 是否同步写入 |
138
+ | options.bufferSize | number | 4096 | 缓冲区大小(字节) |
139
+ | options.isSwitchConsole | (type) => boolean | - | 切换到控制台的条件 |
140
+ | options.outputConsoleFn | OutputConsole | - | 控制台输出函数 |
201
141
 
202
- #### OutputConsoleTypeEnum
142
+ **返回值:** OutputLogFile 混合类型实例
203
143
 
204
- 控制台输出类型枚举:
144
+ **示例:**
205
145
 
206
146
  ```typescript
207
- enum OutputConsoleTypeEnum {
208
- DEBUG = 31, // 调试信息
209
- SKIP = 32, // 跳过
210
- INFO = 33, // 提示信息
211
- TABLE = 34, // 表格
212
- STAGE = 35, // 步骤
213
- SUCCESS = 36, // 成功
214
- WARN = 37, // 警告
215
- ERROR = 38, // 错误
216
- }
217
- ```
218
-
219
- #### OutputLogFileTypeEnum
220
-
221
- 日志文件输出类型枚举(对齐 Pino 标准):
147
+ const logger = createOutputLogFile({
148
+ logFilePath: "app.log",
149
+ sync: false,
150
+ bufferSize: 8192,
151
+ });
222
152
 
223
- ```typescript
224
- enum OutputLogFileTypeEnum {
225
- TRACE = 10, // 跟踪级别
226
- DEBUG = 20, // 调试级别
227
- INFO = 30, // 信息级别
228
- WARN = 40, // 警告级别
229
- ERROR = 50, // 错误级别
230
- FATAL = 60, // 致命错误级别
231
- }
153
+ logger.info("应用启动");
154
+ logger.error("数据库连接失败");
232
155
  ```
233
156
 
234
- ## 高级功能
235
-
236
- ### 临终落盘保护
157
+ ### 输出类型枚举
237
158
 
238
- Node.js 包使用 signal-exit 库实现非侵入式临终落盘保护机制,确保进程退出时日志数据不丢失:
159
+ #### OutputConsoleTypeEnum
239
160
 
240
- ```typescript
241
- import { createOutputLogFile } from "@done-coding/output-node";
161
+ | 值 | 名称 | 说明 |
162
+ | --- | ------- | -------- |
163
+ | 31 | DEBUG | 调试信息 |
164
+ | 32 | SKIP | 跳过 |
165
+ | 33 | INFO | 提示信息 |
166
+ | 34 | TABLE | 表格 |
167
+ | 35 | STAGE | 步骤 |
168
+ | 36 | SUCCESS | 成功 |
169
+ | 37 | WARN | 警告 |
170
+ | 38 | ERROR | 错误 |
242
171
 
243
- // 创建日志实例会自动注册 signal-exit 监听器
244
- const logger = createOutputLogFile({ logFilePath: "app.log" });
172
+ #### OutputLogFileTypeEnum
245
173
 
246
- logger.info("应用启动");
247
- // 当收到 SIGINT SIGTERM 信号时,会自动刷新日志缓冲区
248
- // NestJS 等现代框架的关闭钩子完美兼容
249
- ```
174
+ | 值 | 名称 | 说明 |
175
+ | --- | ----- | ------------ |
176
+ | 10 | TRACE | 跟踪级别 |
177
+ | 20 | DEBUG | 调试级别 |
178
+ | 30 | INFO | 信息级别 |
179
+ | 40 | WARN | 警告级别 |
180
+ | 50 | ERROR | 错误级别 |
181
+ | 60 | FATAL | 致命错误级别 |
250
182
 
251
- ### 错误处理
183
+ ## 进阶使用
252
184
 
253
- 包含完整的错误处理机制:
185
+ ### 切换和同步逻辑
254
186
 
255
187
  ```typescript
256
188
  import {
257
189
  createOutputConsole,
258
- DriverInitializationError,
190
+ createOutputLogFile,
191
+ OutputConsoleTypeEnum,
259
192
  } from "@done-coding/output-node";
260
193
 
261
- try {
262
- const outputConsole = createOutputConsole({
263
- bufferSize: -1, // 无效配置会抛出错误
264
- });
265
- } catch (error) {
266
- if (error instanceof DriverInitializationError) {
267
- console.error("驱动初始化失败:", error.message);
268
- }
269
- }
194
+ // 创建日志文件输出
195
+ const fileLogger = createOutputLogFile({ logFilePath: "error.log" });
196
+
197
+ // 创建带有切换和同步逻辑的控制台输出
198
+ const output = createOutputConsole({
199
+ enableColor: true,
200
+ // 错误级别切换到日志文件(不在控制台显示)
201
+ isSwitchLogFile: (type) => type === OutputConsoleTypeEnum.ERROR,
202
+ // 警告级别同步到日志文件(控制台和文件都显示)
203
+ isSyncToLogFile: (type) => type === OutputConsoleTypeEnum.WARN,
204
+ outputFileFn: fileLogger,
205
+ });
206
+
207
+ output.info("普通信息"); // 只在控制台显示
208
+ output.warn("警告信息"); // 控制台和文件都显示
209
+ output.error("错误信息"); // 只在文件中记录
270
210
  ```
271
211
 
272
212
  ### 自定义颜色配置
@@ -277,7 +217,7 @@ import {
277
217
  OutputConsoleTypeEnum,
278
218
  } from "@done-coding/output-node";
279
219
 
280
- const outputConsole = createOutputConsole({
220
+ const output = createOutputConsole({
281
221
  enableColor: true,
282
222
  colorMap: {
283
223
  [OutputConsoleTypeEnum.INFO]: "blue",
@@ -291,161 +231,118 @@ const outputConsole = createOutputConsole({
291
231
  ### 缓冲区配置
292
232
 
293
233
  ```typescript
294
- import { createOutputLogFile } from "@done-coding/output-node";
295
-
296
- // 自定义缓冲区大小
234
+ // 异步写入模式(推荐用于生产环境)
297
235
  const logger = createOutputLogFile({
298
- bufferSize: 8192, // 8KB 缓冲区
236
+ logFilePath: "app.log",
299
237
  sync: false, // 异步写入
238
+ bufferSize: 8192, // 8KB 缓冲区
300
239
  });
301
240
 
302
241
  // 同步写入模式(性能较低但数据安全性更高)
303
242
  const syncLogger = createOutputLogFile({
243
+ logFilePath: "critical.log",
304
244
  sync: true, // 同步写入
305
245
  bufferSize: 1024, // 较小的缓冲区
306
246
  });
307
247
  ```
308
248
 
309
- ### 工具函数
249
+ ### TABLE 类型处理
310
250
 
311
251
  ```typescript
312
- import {
313
- generateDefaultNodeLogFileName,
314
- getConsoleTypeName,
315
- getLogFileTypeName,
316
- } from "@done-coding/output-node";
252
+ const output = createOutputConsole();
317
253
 
318
- // 生成默认日志文件名
319
- const fileName = generateDefaultNodeLogFileName();
320
- console.log(fileName); // 20240131_235959-12345.log
254
+ // 数组表格
255
+ output.table([
256
+ { name: "张三", age: 25, city: "北京" },
257
+ { name: "李四", age: 30, city: "上海" },
258
+ ]);
321
259
 
322
- // 获取类型名称
323
- console.log(getConsoleTypeName(OutputConsoleTypeEnum.INFO)); // "INFO"
324
- console.log(getLogFileTypeName(OutputLogFileTypeEnum.ERROR)); // "ERROR"
260
+ // 对象表格
261
+ output.table({
262
+ total: 100,
263
+ success: 95,
264
+ failed: 5,
265
+ });
325
266
  ```
326
267
 
327
- ## 最佳实践
328
-
329
- ### 1. 使用属性调用方式
268
+ ### 临终落盘保护
330
269
 
331
270
  ```typescript
332
- // 推荐:属性调用方式
333
- outputConsole.info("用户登录成功");
334
- outputConsole.error("数据库连接失败");
271
+ import { createOutputLogFile } from "@done-coding/output-node";
272
+
273
+ // 创建日志实例会自动注册 signal-exit 监听器
274
+ const logger = createOutputLogFile({ logFilePath: "app.log" });
275
+
276
+ logger.info("应用启动");
335
277
 
336
- // 不推荐:函数调用方式(虽然也支持)
337
- outputConsole(OutputConsoleTypeEnum.INFO, "用户登录成功");
278
+ // 当收到 SIGINT 或 SIGTERM 信号时,会自动刷新日志缓冲区
279
+ // 与 NestJS 等现代框架的关闭钩子完美兼容
338
280
  ```
339
281
 
340
- ### 2. 合理配置日志级别
282
+ ## 开发与测试
341
283
 
342
- ```typescript
343
- // 开发环境
344
- const devLogger = createOutputLogFile({
345
- prettyPrint: true, // 美化输出便于调试
346
- logFilePath: "dev.log",
347
- outputToConsole: true, // 同时输出到控制台
348
- });
284
+ ### 测试覆盖率
349
285
 
350
- // 生产环境
351
- const prodLogger = createOutputLogFile({
352
- prettyPrint: false, // 标准 JSON 格式
353
- logFilePath: `/var/log/app-${process.pid}.log`,
354
- sync: false, // 异步写入提高性能
355
- bufferSize: 8192, // 较大缓冲区
356
- });
357
- ```
286
+ - **语句覆盖率**: 99.22%
287
+ - **分支覆盖率**: 96.27%
288
+ - **函数覆盖率**: 97.72%
289
+ - **行覆盖率**: 99.22%
290
+ - **测试数量**: 211 个测试,全部通过
358
291
 
359
- ### 3. 错误处理和降级
292
+ ### 本地开发
360
293
 
361
- ```typescript
362
- import { createOutputLogFile } from "@done-coding/output-node";
294
+ ```bash
295
+ # 克隆仓库
296
+ git clone https://github.com/done-coding/output-node.git
297
+ cd output-node
363
298
 
364
- try {
365
- const logger = createOutputLogFile({
366
- logFilePath: "/protected/app.log",
367
- bufferSize: 4096,
368
- });
369
- } catch (error) {
370
- // 降级到控制台输出
371
- console.warn("日志文件创建失败,降级到控制台输出");
372
- const fallbackLogger = createOutputLogFile({
373
- outputToConsole: true,
374
- prettyPrint: true,
375
- });
376
- }
377
- ```
299
+ # 安装依赖
300
+ pnpm install
378
301
 
379
- ### 4. 性能优化
302
+ # 开发模式
303
+ pnpm dev
380
304
 
381
- ```typescript
382
- // 在高频输出场景下使用静默模式进行性能测试
383
- const outputConsole = createOutputConsole({
384
- silent: process.env.NODE_ENV === "test",
385
- });
305
+ # 运行测试
306
+ pnpm test
386
307
 
387
- // 批量输出时考虑使用异步日志
388
- const logger = createOutputLogFile({
389
- logFilePath: "batch.log",
390
- prettyPrint: false, // 禁用美化以提高性能
391
- sync: false, // 异步写入
392
- bufferSize: 16384, // 更大的缓冲区
393
- });
308
+ # 构建
309
+ pnpm build
394
310
  ```
395
311
 
396
- ### 5. TABLE 类型最佳实践
312
+ ### 贡献流程
397
313
 
398
- ```typescript
399
- // 推荐:结构化数据
400
- outputConsole.table([
401
- { name: "张三", age: 25, city: "北京" },
402
- { name: "李四", age: 30, city: "上海" },
403
- ]);
314
+ 1. Fork 本仓库
315
+ 2. 创建特性分支 (`git checkout -b feature/AmazingFeature`)
316
+ 3. 提交更改 (`git commit -m 'Add some AmazingFeature'`)
317
+ 4. 推送到分支 (`git push origin feature/AmazingFeature`)
318
+ 5. 开启 Pull Request
404
319
 
405
- // ✅ 推荐:对象数据
406
- outputConsole.table({
407
- total: 100,
408
- success: 95,
409
- failed: 5,
410
- });
320
+ ## 常见问题
411
321
 
412
- // 避免:非结构化数据
413
- outputConsole.table("这不是表格数据");
414
- ```
322
+ **Q: 如何在 NestJS 中使用?**
415
323
 
416
- ## 依赖
324
+ A: 可以在 NestJS 的 OnModuleInit 和 OnApplicationShutdown 钩子中使用,临终落盘保护会自动处理进程退出时的日志刷新。
417
325
 
418
- - `@done-coding/output-core` - 核心包
419
- - `chalk` - 控制台颜色输出
420
- - `pino` - 高性能日志库
421
- - `pino-pretty` - 日志美化输出
422
- - `signal-exit` - 非侵入式进程退出监听
326
+ **Q: 日志文件路径可以是相对路径吗?**
423
327
 
424
- ## 测试覆盖率
328
+ A: 可以,相对路径会相对于当前工作目录。建议使用绝对路径以避免歧义。
425
329
 
426
- - **语句覆盖率**: 99.51%
427
- - **分支覆盖率**: 98.13%
428
- - **函数覆盖率**: 97.29%
429
- - **行覆盖率**: 99.51%
430
- - **测试数量**: 182 个测试,全部通过
330
+ **Q: 如何禁用颜色输出?**
431
331
 
432
- ## 许可证
332
+ A: 设置 `enableColor: false` 即可。
433
333
 
434
- MIT
334
+ **Q: 缓冲区大小应该设置多少?**
435
335
 
436
- ## 贡献
336
+ A: 默认 4KB 适合大多数场景。高频输出可以增加到 8KB 或 16KB,低频输出可以减少到 1KB。
437
337
 
438
- 欢迎提交 Issue Pull Request!
338
+ **Q: 支持哪些 Node.js 版本?**
439
339
 
440
- ## 更新日志
340
+ A: 支持 Node.js 14+,推荐使用 Node.js 16+。
441
341
 
442
- ### v0.0.0
342
+ **Q: 如何处理日志文件权限错误?**
443
343
 
444
- - 初始版本发布
445
- - 支持控制台输出和日志文件输出
446
- - 实现基于 signal-exit 的临终落盘保护机制
447
- - 完整的错误处理和类型推导支持
448
- - 输出模式切换功能
449
- - TABLE 类型特殊处理
450
- - 常量集中管理
451
- - 缓冲区大小配置和验证
344
+ A: 包会自动捕获权限错误并静默处理,日志会降级到内存缓冲。建议检查文件路径和目录权限。
345
+
346
+ ## 许可证
347
+
348
+ MIT
package/es/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { OutputConsoleTypeEnum as c, OutputLogFileTypeEnum as E, handleTableTypeConsole as Z, generateTimestamp as x, createOutputConsole as z, createOutputLogFile as G } from "@done-coding/output-core";
3
- import { OutputConsoleTypeEnum as pe, OutputLogFileTypeEnum as Ee, OutputTargetModeEnum as ye } from "@done-coding/output-core";
3
+ import { OutputConsoleTypeEnum as pe, OutputLogFileTypeEnum as Ee } from "@done-coding/output-core";
4
4
  import p from "chalk";
5
5
  import h from "pino";
6
6
  import F from "node:fs";
@@ -405,7 +405,6 @@ export {
405
405
  N as InvalidOutputTypeError,
406
406
  pe as OutputConsoleTypeEnum,
407
407
  Ee as OutputLogFileTypeEnum,
408
- ye as OutputTargetModeEnum,
409
408
  fe as createOutputConsole,
410
409
  ce as createOutputLogFile,
411
410
  ae as createPinoConsoleOutput,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@done-coding/output-node",
3
- "version": "0.1.0-alpha.0",
3
+ "version": "0.1.0",
4
4
  "description": "node相关输出",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -54,10 +54,10 @@
54
54
  "signal-exit": "^4.1.0"
55
55
  },
56
56
  "dependencies": {
57
- "@done-coding/output-core": "0.1.0-alpha.0"
57
+ "@done-coding/output-core": "0.1.0"
58
58
  },
59
59
  "engines": {
60
60
  "node": ">=18.0.0"
61
61
  },
62
- "gitHead": "4365181831a85aa7dd657faac9af146ad0a5739d"
62
+ "gitHead": "fe3595bcf072441befe269e1b1e47c807ae7e0e5"
63
63
  }
package/types/index.d.ts CHANGED
@@ -6,7 +6,6 @@ import { OutputConsoleTypeEnum } from '@done-coding/output-core';
6
6
  import { OutputLogFile } from '@done-coding/output-core';
7
7
  import { OutputLogFileRaw } from '@done-coding/output-core';
8
8
  import { OutputLogFileTypeEnum } from '@done-coding/output-core';
9
- import { OutputTargetModeEnum } from '@done-coding/output-core';
10
9
 
11
10
  /**
12
11
  * 缓冲区大小配置常量
@@ -221,6 +220,4 @@ export { OutputLogFileRaw }
221
220
 
222
221
  export { OutputLogFileTypeEnum }
223
222
 
224
- export { OutputTargetModeEnum }
225
-
226
223
  export { }