@aomex/logger 3.30.7 → 3.30.8-alpha.62.sha-92b25bb
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 +3 -0
- package/dist/index.d.ts +377 -139
- package/dist/index.js +547 -181
- package/dist/index.js.map +1 -1
- package/package.json +23 -16
package/README.md
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -1,145 +1,383 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
import { Service } from "@aomex/common";
|
|
2
|
+
import { styleText } from "node:util";
|
|
3
|
+
import tty from "node:tty";
|
|
4
|
+
import { Mode } from "node:fs";
|
|
5
|
+
import { Writable } from "node:stream";
|
|
6
|
+
/**
|
|
7
|
+
* 标准日志等级(低 → 高)。选用约定:
|
|
8
|
+
* - `trace`:极细诊断(逐步追踪、协议帧、循环内细节);生产建议在 transport 上门禁关掉
|
|
9
|
+
* - `debug`:开发调试(关键变量、分支走向);生产建议在 transport 上门禁关掉
|
|
10
|
+
* - `info`:正常业务事件(启动、请求完成、任务成功)
|
|
11
|
+
* - `warn`:可恢复异常或需关注的降级(重试、兜底、配置不当)
|
|
12
|
+
* - `error`:请求/任务失败,服务仍可继续(未处理异常、下游失败)
|
|
13
|
+
* - `fatal`:进程级致命错误,随后通常应退出(启动失败、数据损坏)
|
|
14
|
+
*
|
|
15
|
+
* 框架不会按 `NODE_ENV` 自动过滤;未配 `TransportEntry.level` 时六级全开。
|
|
16
|
+
*/
|
|
17
|
+
export declare const LOGGER_LEVELS: readonly ['trace', 'debug', 'info', 'warn', 'error', 'fatal'];
|
|
18
|
+
export type LoggerLevel = (typeof LOGGER_LEVELS)[number];
|
|
19
|
+
/**
|
|
20
|
+
* 等级门槛:
|
|
21
|
+
* - 单个 level:视为最低等级(含该级及以上)
|
|
22
|
+
* - `{ min, max? }` / `{ min?, max }`:闭区间,至少指定一端
|
|
23
|
+
*/
|
|
24
|
+
export type LoggerLevelGate = LoggerLevel | {
|
|
25
|
+
min: LoggerLevel;
|
|
26
|
+
max?: LoggerLevel;
|
|
27
|
+
} | {
|
|
28
|
+
min?: LoggerLevel;
|
|
29
|
+
max: LoggerLevel;
|
|
30
|
+
};
|
|
31
|
+
/** 序列化后的异常(`type` / `message` / `stack` / `cause`) */
|
|
32
|
+
export interface SerializedError {
|
|
33
|
+
type: string;
|
|
34
|
+
message: string;
|
|
35
|
+
stack?: string;
|
|
36
|
+
cause?: SerializedError;
|
|
22
37
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
38
|
+
/** `withBindings()` 挂上的结构化上下文(任意业务键值) */
|
|
39
|
+
export type LoggerBindings = Record<string, unknown>;
|
|
40
|
+
export interface LogRecord {
|
|
41
|
+
timestamp: Date;
|
|
42
|
+
level: LoggerLevel;
|
|
43
|
+
message: string;
|
|
44
|
+
exception?: SerializedError;
|
|
45
|
+
/** 来自 `withBindings()` 异步上下文的结构化字段 */
|
|
46
|
+
bindings?: LoggerBindings;
|
|
30
47
|
}
|
|
31
|
-
|
|
32
|
-
declare class
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
48
|
+
export type TransportFormat = 'text' | 'json';
|
|
49
|
+
export declare abstract class Transport {
|
|
50
|
+
abstract consume(log: LogRecord): Promise<any>;
|
|
51
|
+
/**
|
|
52
|
+
* 异步初始化。`BaseLoggerService` 在首次投递 / 服务 `onInit` 时会等待全部 transport 完成。
|
|
53
|
+
* 默认无操作。
|
|
54
|
+
*/
|
|
55
|
+
onInit(): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* 刷出 transport 内部缓冲(若有)。默认无操作。
|
|
58
|
+
*/
|
|
59
|
+
flush(): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* 异步销毁。服务 `onDestroy` 在 `flush` 之后会等待全部 transport 完成。
|
|
62
|
+
* 默认无操作。
|
|
63
|
+
*/
|
|
64
|
+
onDestroy(): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* 解析日期。返回 年、月、日、时、分、秒
|
|
67
|
+
*/
|
|
68
|
+
protected dateToJSON(date: Date): {
|
|
69
|
+
year: string;
|
|
70
|
+
month: string;
|
|
71
|
+
day: string;
|
|
72
|
+
hour: string;
|
|
73
|
+
minute: string;
|
|
74
|
+
second: string;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* 时间字符串:`年-月-日 时:分:秒`
|
|
78
|
+
*/
|
|
79
|
+
protected dateToString(date: Date): string;
|
|
80
|
+
/**
|
|
81
|
+
* 格式化单条日志。
|
|
82
|
+
* - `text`:`[level] time message`,有 `bindings` / `exception` 时追加
|
|
83
|
+
* - `json`:NDJSON(`time` / `level` / `message`,可选 `exception` / `bindings`)
|
|
84
|
+
*/
|
|
85
|
+
protected formatLog(log: LogRecord, format?: TransportFormat): string;
|
|
40
86
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
87
|
+
export declare namespace BaseLoggerService {
|
|
88
|
+
type Level = LoggerLevel;
|
|
89
|
+
type LevelGate = LoggerLevelGate;
|
|
90
|
+
interface TransportEntry {
|
|
91
|
+
transport: Transport;
|
|
92
|
+
/**
|
|
93
|
+
* 该 transport 的等级门槛。默认全开。
|
|
94
|
+
* - `'warn'`:warn 及以上
|
|
95
|
+
* - `{ min: 'info', max: 'error' }`:闭区间
|
|
96
|
+
*/
|
|
97
|
+
level?: LevelGate;
|
|
98
|
+
/**
|
|
99
|
+
* 为 `true` 时跳过该 transport(不 `onInit` / 不投递 / 不 `flush` / 不 `onDestroy`)。
|
|
100
|
+
*/
|
|
101
|
+
disabled?: boolean;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export declare abstract class BaseLoggerService extends Service {
|
|
105
|
+
private readonly logs;
|
|
106
|
+
private transportGates;
|
|
107
|
+
private timer?;
|
|
108
|
+
private readyPromise?;
|
|
109
|
+
private readonly bindingsStorage;
|
|
110
|
+
protected abstract createTransports(): BaseLoggerService.TransportEntry[];
|
|
111
|
+
protected onInit(): Promise<void>;
|
|
112
|
+
protected onDestroy(): Promise<void>;
|
|
113
|
+
/** 等待内存队列输送完毕,并 flush 各 transport 内部缓冲 */
|
|
114
|
+
flush(): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* 极细诊断(逐步追踪、协议细节等)。仅文案;异常请用 `warn` / `error` / `fatal`。
|
|
117
|
+
* 生产是否输出取决于 transport 的 `level` 门禁(框架不按 `NODE_ENV` 自动关)。
|
|
118
|
+
*/
|
|
119
|
+
trace(message: string): void;
|
|
120
|
+
/**
|
|
121
|
+
* 开发调试(关键变量、分支走向)。仅文案;异常请用 `warn` / `error` / `fatal`。
|
|
122
|
+
* 生产是否输出取决于 transport 的 `level` 门禁(框架不按 `NODE_ENV` 自动关)。
|
|
123
|
+
*/
|
|
124
|
+
debug(message: string): void;
|
|
125
|
+
/**
|
|
126
|
+
* 正常业务事件(启动就绪、请求/任务成功等)。仅文案;异常请用 `warn` / `error` / `fatal`。
|
|
127
|
+
*/
|
|
128
|
+
info(message: string): void;
|
|
129
|
+
/**
|
|
130
|
+
* 可恢复异常或需关注的降级(重试、兜底、配置不当)。可带 `err`。
|
|
131
|
+
*/
|
|
132
|
+
warn(message: string): void;
|
|
133
|
+
warn(err: unknown): void;
|
|
134
|
+
warn(err: unknown, message: string): void;
|
|
135
|
+
/**
|
|
136
|
+
* 请求/任务失败,进程通常仍可继续(未处理异常、下游失败)。可带 `err`。
|
|
137
|
+
*/
|
|
138
|
+
error(message: string): void;
|
|
139
|
+
error(err: unknown): void;
|
|
140
|
+
error(err: unknown, message: string): void;
|
|
141
|
+
/**
|
|
142
|
+
* 进程级致命错误(启动失败、数据损坏等),打完后通常应退出。可带 `err`。
|
|
143
|
+
*/
|
|
144
|
+
fatal(message: string): void;
|
|
145
|
+
fatal(err: unknown): void;
|
|
146
|
+
fatal(err: unknown, message: string): void;
|
|
147
|
+
/**
|
|
148
|
+
* 在异步上下文中挂上 `bindings`,回调内(含 `await`)写出的日志都会带上这些字段。
|
|
149
|
+
* 嵌套 `withBindings` 时与外层合并,同名键由内层覆盖。始终返回 `Promise`。
|
|
150
|
+
*
|
|
151
|
+
* ```typescript
|
|
152
|
+
* await logger.withBindings({ requestId: 'req-1' }, async () => {
|
|
153
|
+
* logger.info('ok');
|
|
154
|
+
* });
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
withBindings<T>(bindings: LoggerBindings, callback: () => Promise<T>): Promise<T>;
|
|
158
|
+
/** 当前异步上下文中的 bindings(浅拷贝);无上下文时为空对象 */
|
|
159
|
+
bindings(): LoggerBindings;
|
|
160
|
+
/**
|
|
161
|
+
* 写入一条日志。子类自定义方法时可复用。
|
|
162
|
+
*
|
|
163
|
+
* - `write('info', 'hello')`
|
|
164
|
+
* - `write('warn', err)` / `write('error', err)` — `err` 为 `unknown`(含 `catch` 值)
|
|
165
|
+
* - `write('error', err, 'checkout failed')`
|
|
166
|
+
*/
|
|
167
|
+
protected write(level: LoggerLevel, messageOrError: unknown, message?: string): void;
|
|
168
|
+
/**
|
|
169
|
+
* 将任意抛出值序列化为 `exception` 字段(`Error` 走完整 stack/cause,其它值降级)。
|
|
170
|
+
*/
|
|
171
|
+
protected serializeUnknown(value: unknown, seen?: WeakSet<object>): SerializedError;
|
|
172
|
+
/** `Error` 专用入口,等价于 `serializeUnknown(err)` */
|
|
173
|
+
protected serializeError(err: Error, seen?: WeakSet<object>): SerializedError;
|
|
174
|
+
/**
|
|
175
|
+
* - 仅传 `string` → 普通文案,不挂 `exception`
|
|
176
|
+
* - 传 `unknown`(可再跟 message)→ 序列化到 `exception`
|
|
177
|
+
*/
|
|
178
|
+
protected normalizeLogArgs(messageOrError: unknown, message?: string): {
|
|
179
|
+
message: string;
|
|
180
|
+
exception?: SerializedError;
|
|
181
|
+
};
|
|
182
|
+
/** 将 gate 解析为闭区间下标 */
|
|
183
|
+
protected resolveLevelGate(gate: LoggerLevelGate | undefined): {
|
|
184
|
+
minIndex: number;
|
|
185
|
+
maxIndex: number;
|
|
186
|
+
};
|
|
187
|
+
/** 判断某等级是否落在 gate 闭区间内 */
|
|
188
|
+
protected isLevelEnabled(level: LoggerLevel, gate: LoggerLevelGate | undefined): boolean;
|
|
189
|
+
/**
|
|
190
|
+
* 创建 transports 并等待各自 `onInit`。可重入,只执行一次。
|
|
191
|
+
*/
|
|
192
|
+
private ensureReady;
|
|
193
|
+
private consume;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* 自定义消费逻辑;`this` 绑定为 Transport,可复用 `formatLog` / `dateToString`。
|
|
197
|
+
*
|
|
198
|
+
* ```typescript
|
|
199
|
+
* new CustomTransport({
|
|
200
|
+
* consume(log) {
|
|
201
|
+
* // 例如推到自建队列、写数据库等
|
|
202
|
+
* console.log(this.formatLog(log, 'json'));
|
|
203
|
+
* },
|
|
204
|
+
* });
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
export declare class CustomTransport extends Transport {
|
|
208
|
+
protected readonly consumeHandle: (this: Transport, log: LogRecord) => void | Promise<void>;
|
|
209
|
+
constructor(opts: {
|
|
210
|
+
consume: (this: Transport, log: LogRecord) => void | Promise<void>;
|
|
211
|
+
});
|
|
212
|
+
consume(log: LogRecord): Promise<void>;
|
|
213
|
+
}
|
|
214
|
+
type Style = Parameters<typeof styleText>[0];
|
|
215
|
+
export declare class ConsoleTransport extends Transport {
|
|
216
|
+
protected readonly format: TransportFormat;
|
|
217
|
+
protected readonly colorize: boolean;
|
|
218
|
+
protected readonly colors: Record<string, Style>;
|
|
219
|
+
protected readonly stdout: tty.WriteStream;
|
|
220
|
+
protected readonly stderr: tty.WriteStream;
|
|
221
|
+
protected readonly stderrLevelSet: Set<LoggerLevel>;
|
|
222
|
+
/** 若构造时显式传入 `output`,则所有等级走同一流 */
|
|
223
|
+
protected readonly forcedOutput?: tty.WriteStream;
|
|
224
|
+
constructor(opts?: {
|
|
225
|
+
/**
|
|
226
|
+
* 输出格式。默认 `text`;生产采集建议 `json`。
|
|
227
|
+
*/
|
|
228
|
+
format?: TransportFormat;
|
|
229
|
+
/**
|
|
230
|
+
* 是否着色。默认:`text` 且目标流为 TTY 时开启。
|
|
231
|
+
*/
|
|
232
|
+
colorize?: boolean;
|
|
233
|
+
/**
|
|
234
|
+
* 覆盖默认等级颜色。
|
|
235
|
+
*/
|
|
236
|
+
colors?: Partial<Record<LoggerLevel, Style>>;
|
|
237
|
+
/**
|
|
238
|
+
* 固定输出流(设置后忽略 `stderrLevels` 分流)。
|
|
239
|
+
*/
|
|
240
|
+
output?: tty.WriteStream;
|
|
241
|
+
/**
|
|
242
|
+
* 未设置 `output` 时,这些等级写入 stderr。默认 `error` / `fatal`。
|
|
243
|
+
*/
|
|
244
|
+
stderrLevels?: LoggerLevel[];
|
|
245
|
+
stdout?: tty.WriteStream;
|
|
246
|
+
stderr?: tty.WriteStream;
|
|
247
|
+
});
|
|
248
|
+
consume(log: LogRecord): Promise<any>;
|
|
249
|
+
protected resolveWriter(level: LoggerLevel): tty.WriteStream;
|
|
250
|
+
protected render(log: LogRecord): string;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* 追加写入本地日志文件;目录不存在时自动创建。
|
|
254
|
+
*
|
|
255
|
+
* ```typescript
|
|
256
|
+
* // 使用默认路径:./logs/{year}-{month}-{day}/{level}.log
|
|
257
|
+
* new FileTransport();
|
|
258
|
+
*
|
|
259
|
+
* new FileTransport({
|
|
260
|
+
* file: './logs/app.log',
|
|
261
|
+
* format: 'json',
|
|
262
|
+
* });
|
|
263
|
+
*
|
|
264
|
+
* new FileTransport({
|
|
265
|
+
* file: (log) => `./logs/${log.level}.log`,
|
|
266
|
+
* });
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
export declare class FileTransport extends Transport {
|
|
270
|
+
protected readonly file: string | ((log: LogRecord) => string);
|
|
271
|
+
protected readonly fileMode?: Mode;
|
|
272
|
+
protected readonly dirMode?: Mode;
|
|
273
|
+
protected readonly format: TransportFormat;
|
|
274
|
+
protected readonly ensuredDirs: Set<string>;
|
|
275
|
+
constructor(opts?: {
|
|
276
|
+
/**
|
|
277
|
+
* 日志文件路径,支持占位符。默认 `./logs/{year}-{month}-{day}/{level}.log`。
|
|
278
|
+
* - `{year}` 年
|
|
279
|
+
* - `{month}` 月
|
|
280
|
+
* - `{day}` 日
|
|
281
|
+
* - `{hour}` 时
|
|
282
|
+
* - `{minute}` 分
|
|
283
|
+
* - `{second}` 秒
|
|
284
|
+
* - `{level}` 日志等级
|
|
285
|
+
*/
|
|
286
|
+
file?: string | ((log: LogRecord) => string);
|
|
287
|
+
/**
|
|
288
|
+
* 输出格式。默认 `text`;采集管道建议 `json`(每行一条 NDJSON)。
|
|
289
|
+
*/
|
|
290
|
+
format?: TransportFormat;
|
|
291
|
+
/**
|
|
292
|
+
* 文件权限,默认使用系统权限
|
|
293
|
+
*/
|
|
294
|
+
fileMode?: Mode;
|
|
295
|
+
/**
|
|
296
|
+
* 文件夹权限,默认使用系统权限
|
|
297
|
+
*/
|
|
298
|
+
dirMode?: Mode;
|
|
299
|
+
});
|
|
300
|
+
consume(log: LogRecord): Promise<any>;
|
|
301
|
+
protected resolveFilePath(log: LogRecord): string;
|
|
302
|
+
protected getContent(log: LogRecord): string;
|
|
74
303
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
level: Level<NoInfer<T>>;
|
|
102
|
-
}[];
|
|
103
|
-
}
|
|
104
|
-
interface Log<T extends string = string> {
|
|
105
|
-
timestamp: Date;
|
|
106
|
-
level: T;
|
|
107
|
-
content: string;
|
|
108
|
-
}
|
|
304
|
+
/**
|
|
305
|
+
* 写入任意 Writable 流。
|
|
306
|
+
*
|
|
307
|
+
* ```typescript
|
|
308
|
+
* import { PassThrough } from 'node:stream';
|
|
309
|
+
*
|
|
310
|
+
* new StreamTransport({
|
|
311
|
+
* stream: process.stdout,
|
|
312
|
+
* format: 'json',
|
|
313
|
+
* });
|
|
314
|
+
*
|
|
315
|
+
* const sink = new PassThrough();
|
|
316
|
+
* new StreamTransport({ stream: sink });
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
319
|
+
export declare class StreamTransport extends Transport {
|
|
320
|
+
protected readonly stream: Writable;
|
|
321
|
+
protected readonly format: TransportFormat;
|
|
322
|
+
constructor(opts: {
|
|
323
|
+
stream: Writable;
|
|
324
|
+
/**
|
|
325
|
+
* 输出格式。默认 `text`。
|
|
326
|
+
*/
|
|
327
|
+
format?: TransportFormat;
|
|
328
|
+
});
|
|
329
|
+
consume(log: LogRecord): Promise<void>;
|
|
109
330
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
331
|
+
type FetchHeaders = NonNullable<RequestInit['headers']>;
|
|
332
|
+
type FetchBody = NonNullable<RequestInit['body']>;
|
|
333
|
+
/**
|
|
334
|
+
* 通过 HTTP 将日志推送到 Webhook 地址
|
|
335
|
+
*
|
|
336
|
+
* ```typescript
|
|
337
|
+
* new WebhookTransport({
|
|
338
|
+
* url: process.env.ALERT_WEBHOOK_URL!,
|
|
339
|
+
* });
|
|
340
|
+
*
|
|
341
|
+
* new WebhookTransport({
|
|
342
|
+
* url: 'https://example.com/hook',
|
|
343
|
+
* headers: { Authorization: 'Bearer xxx' },
|
|
344
|
+
* format: (log) => JSON.stringify({ text: log.message }),
|
|
345
|
+
* });
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
348
|
+
export declare class WebhookTransport extends Transport {
|
|
349
|
+
protected readonly url: string;
|
|
350
|
+
protected readonly method: string;
|
|
351
|
+
protected readonly headers?: FetchHeaders;
|
|
352
|
+
protected readonly format: TransportFormat | ((log: LogRecord) => FetchBody | Promise<FetchBody>);
|
|
353
|
+
protected readonly timeoutMs: number;
|
|
354
|
+
constructor(opts: {
|
|
355
|
+
/**
|
|
356
|
+
* Webhook 地址。
|
|
357
|
+
*/
|
|
358
|
+
url: string | URL;
|
|
359
|
+
/**
|
|
360
|
+
* HTTP 方法。默认 `POST`。
|
|
361
|
+
*/
|
|
362
|
+
method?: string;
|
|
363
|
+
/**
|
|
364
|
+
* 额外请求头。未指定 `Content-Type` 时,`json` / `text` 格式会自动补上。
|
|
365
|
+
*/
|
|
366
|
+
headers?: FetchHeaders;
|
|
367
|
+
/**
|
|
368
|
+
* 请求体。默认 `json`(`formatLog` 的 JSON 字符串)。
|
|
369
|
+
* 传入函数时可按对端协议自行组装 body。
|
|
370
|
+
*/
|
|
371
|
+
format?: TransportFormat | ((log: LogRecord) => FetchBody | Promise<FetchBody>);
|
|
372
|
+
/**
|
|
373
|
+
* 请求超时(毫秒)。默认 `30_000`。
|
|
374
|
+
*/
|
|
375
|
+
timeoutMs?: number;
|
|
376
|
+
});
|
|
377
|
+
consume(log: LogRecord): Promise<void>;
|
|
378
|
+
protected buildBody(log: LogRecord): Promise<{
|
|
379
|
+
body: FetchBody;
|
|
380
|
+
contentType?: string;
|
|
381
|
+
}>;
|
|
143
382
|
}
|
|
144
|
-
|
|
145
|
-
export { Logger, Transport };
|
|
383
|
+
export {};
|