@rawnodes/logger 2.9.0 → 2.11.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/dist/index.d.ts CHANGED
@@ -1,244 +1,7 @@
1
+ import { L as LoggerContext, a as LoggerConfig, b as LevelOverrideMatch, c as LogLevel, d as LevelOverride, M as Meta, D as DiscordConfig, T as TelegramConfig, C as CloudWatchConfig, e as MaskReplacer, Z as ZohoCliqConfig, f as CallerConfig, g as CallerInfo, h as LogFormat, i as LevelRule, j as ConsoleConfig, F as FileConfig, H as HttpTransportBaseConfig, k as LevelConfigObject, l as LevelConfig, R as RelayConfig, A as AutoShutdownConfig, m as LogStreamPattern, n as LogStreamPatternConfig, o as LogStreamTemplateConfig, p as LogStreamName } from './types-lfJLhC8J.js';
2
+ export { q as LOG_LEVELS, x as MaskSecretsOptions, t as ZohoCliqBotConfig, s as assertLogLevel, v as createMasker, r as isValidLogLevel, w as maskReplacer, u as maskSecrets } from './types-lfJLhC8J.js';
1
3
  import { z } from 'zod';
2
4
 
3
- declare const LOG_LEVELS: {
4
- readonly off: -1;
5
- readonly error: 0;
6
- readonly warn: 1;
7
- readonly info: 2;
8
- readonly http: 3;
9
- readonly verbose: 4;
10
- readonly debug: 5;
11
- readonly silly: 6;
12
- };
13
- type LogLevel = keyof typeof LOG_LEVELS;
14
- declare function isValidLogLevel(level: string): level is LogLevel;
15
- declare function assertLogLevel(level: string): asserts level is LogLevel;
16
- type LogFormat = 'json' | 'plain' | 'logfmt' | 'simple';
17
- interface LevelRule {
18
- match: Record<string, unknown> & {
19
- context?: string;
20
- };
21
- level: LogLevel;
22
- }
23
- /**
24
- * Controls whether a transport respects runtime level overrides registered via
25
- * `setLevelOverride(...)` (or the top-level `level.rules` in the logger config).
26
- *
27
- * When `true` (the default for observability transports — console/file/cloudwatch/relay):
28
- * a matching override bypasses the transport's own `level`/`rules` so that
29
- * targeted troubleshooting actually surfaces logs in the viewing channels.
30
- *
31
- * When `false` (the default for alert-style transports — discord/telegram/zohoCliq):
32
- * the transport filters strictly by its own `level`/`rules` and ignores runtime
33
- * overrides, which prevents ad-hoc debug overrides from flooding user-facing
34
- * notification channels.
35
- *
36
- * Every transport config accepts this flag; the only time it needs to be set
37
- * explicitly is when overriding the default for the transport kind.
38
- */
39
- type RespectRuntimeOverrides = boolean;
40
- interface ConsoleConfig {
41
- format: LogFormat;
42
- level?: LogLevel;
43
- rules?: LevelRule[];
44
- respectRuntimeOverrides?: RespectRuntimeOverrides;
45
- }
46
- interface FileConfig {
47
- format: LogFormat;
48
- level?: LogLevel;
49
- rules?: LevelRule[];
50
- respectRuntimeOverrides?: RespectRuntimeOverrides;
51
- dirname: string;
52
- filename: string;
53
- datePattern?: string;
54
- interval?: string;
55
- zippedArchive?: boolean;
56
- maxSize?: string;
57
- maxFiles?: string;
58
- }
59
- interface HttpTransportBaseConfig {
60
- level?: LogLevel;
61
- rules?: LevelRule[];
62
- respectRuntimeOverrides?: RespectRuntimeOverrides;
63
- batchSize?: number;
64
- flushInterval?: number;
65
- maxRetries?: number;
66
- retryDelay?: number;
67
- /**
68
- * Maximum number of messages the in-memory queue will hold before dropping.
69
- * Provides a hard upper bound on memory usage when a transport is degraded
70
- * or offline — without this, a failing transport + steady log volume grows
71
- * the queue until OOM. Default: unbounded.
72
- *
73
- * Recommended for production: `10_000` — enough to absorb transient blips,
74
- * small enough to avoid runaway memory.
75
- */
76
- maxQueueSize?: number;
77
- /**
78
- * Policy applied when the queue is full.
79
- * - `'drop-oldest'` (default): prefers keeping recent events — during an
80
- * outage old logs are usually stale.
81
- * - `'drop-newest'`: prefers preserving historical context — useful if you
82
- * care more about the events leading up to the outage than the noise
83
- * happening during it.
84
- */
85
- dropPolicy?: 'drop-oldest' | 'drop-newest';
86
- /**
87
- * Called when messages are dropped due to queue overflow. Receives only the
88
- * messages that were discarded. If not provided, drops are silent.
89
- *
90
- * Callback MUST NOT throw; if it does, the exception is swallowed.
91
- */
92
- onDrop?: (droppedMessages: unknown[]) => void;
93
- /**
94
- * Called when a batch fails after all retries and messages are dropped.
95
- * If not provided, the error is logged to stderr.
96
- *
97
- * The callback MUST NOT throw; if it does, the failure is swallowed and a
98
- * stderr fallback is used. This is intentional — a logger must never
99
- * propagate its own transport errors back into the host application.
100
- */
101
- onError?: (error: Error, droppedMessages: unknown[]) => void;
102
- /**
103
- * Timeout in milliseconds for a single outbound HTTP request. Default:
104
- * `10_000`. Applies to Discord/Telegram `fetch`. CloudWatch uses the AWS
105
- * SDK's own timeout configuration.
106
- */
107
- requestTimeout?: number;
108
- }
109
- interface DiscordConfig extends HttpTransportBaseConfig {
110
- webhookUrl: string;
111
- format?: 'embed' | 'markdown';
112
- username?: string;
113
- avatarUrl?: string;
114
- embedColors?: Partial<Record<LogLevel, number>>;
115
- includeTimestamp?: boolean;
116
- includeMeta?: boolean;
117
- maxEmbedFields?: number;
118
- }
119
- interface TelegramConfig extends HttpTransportBaseConfig {
120
- botToken: string;
121
- chatId: string | number;
122
- parseMode?: 'Markdown' | 'MarkdownV2' | 'HTML';
123
- disableNotification?: boolean;
124
- threadId?: number;
125
- replyToMessageId?: number;
126
- }
127
- interface ZohoCliqBotConfig {
128
- /** Bot display name (shown in the channel). */
129
- name: string;
130
- /** Optional bot avatar URL. */
131
- image?: string;
132
- }
133
- interface ZohoCliqConfig extends HttpTransportBaseConfig {
134
- /**
135
- * Incoming webhook URL. If provided, `companyId`/`channel`/`region` are
136
- * ignored and this URL is used as-is (with `zapikey` appended as query).
137
- */
138
- webhookUrl?: string;
139
- /** Zoho Cliq company/org ID. Required unless `webhookUrl` is set. */
140
- companyId?: string;
141
- /** Target channel name (the `channelsbyname` API segment). Required unless `webhookUrl` is set. */
142
- channel?: string;
143
- /** Zoho region/TLD: 'eu' | 'com' | 'in' | etc. Default: 'eu'. */
144
- region?: string;
145
- /** Zoho API key (zapikey). Required. */
146
- apiKey: string;
147
- /** If true (default), message is posted as a broadcast so all members are notified. */
148
- broadcast?: boolean;
149
- /** Post as a custom bot instead of the default user. */
150
- bot?: ZohoCliqBotConfig;
151
- /** Include ISO timestamp in each formatted message. Default: true. */
152
- includeTimestamp?: boolean;
153
- /** Include meta as a fenced code block. Default: true. */
154
- includeMeta?: boolean;
155
- }
156
- type LogStreamPattern = 'hostname' | 'hostname-date' | 'hostname-uuid' | 'date' | 'uuid';
157
- interface LogStreamPatternConfig {
158
- pattern: LogStreamPattern;
159
- }
160
- interface LogStreamTemplateConfig {
161
- /** Custom template with variables: {hostname}, {date}, {datetime}, {uuid}, {pid}, {env} */
162
- template: string;
163
- }
164
- type LogStreamName = string | LogStreamPatternConfig | LogStreamTemplateConfig;
165
- interface RelayConfig {
166
- /** URL of the relay API (e.g., https://relay.example.com) */
167
- apiUrl: string;
168
- /** Authentication token for the relay server */
169
- token: string;
170
- /** Polling interval in ms (default: 30000) */
171
- pollInterval?: number;
172
- /** Ring buffer capacity - max logs held during reconnect (default: 1000) */
173
- bufferSize?: number;
174
- /** WebSocket reconnect base delay in ms (default: 1000) */
175
- reconnectDelay?: number;
176
- /** Max reconnect delay in ms (default: 30000) */
177
- maxReconnectDelay?: number;
178
- /** See RespectRuntimeOverrides. Default: true (relay is an observability transport). */
179
- respectRuntimeOverrides?: RespectRuntimeOverrides;
180
- }
181
- interface CloudWatchConfig extends HttpTransportBaseConfig {
182
- logGroupName: string;
183
- /** Log stream name - string, pattern config, or template config. Defaults to hostname pattern */
184
- logStreamName?: LogStreamName;
185
- region: string;
186
- accessKeyId: string;
187
- secretAccessKey: string;
188
- createLogGroup?: boolean;
189
- createLogStream?: boolean;
190
- }
191
- interface LevelConfigObject {
192
- default: LogLevel;
193
- rules?: LevelRule[];
194
- }
195
- type LevelConfig = LogLevel | LevelConfigObject;
196
- interface CallerConfig {
197
- /** Stack depth to capture (default: 1). Higher values trace further up the call stack */
198
- depth?: number;
199
- /** Include full file path (default: false). If false, shows relative or basename only */
200
- fullPath?: boolean;
201
- }
202
- interface CallerInfo {
203
- file: string;
204
- line: number;
205
- column?: number;
206
- function?: string;
207
- }
208
- interface AutoShutdownConfig {
209
- /** Timeout in ms before forcing exit (default: 5000) */
210
- timeout?: number;
211
- /** Custom signals to handle (default: ['SIGTERM', 'SIGINT']) */
212
- signals?: NodeJS.Signals[];
213
- }
214
- interface LoggerConfig {
215
- level: LevelConfig;
216
- console: ConsoleConfig;
217
- file?: FileConfig;
218
- discord?: DiscordConfig | DiscordConfig[];
219
- telegram?: TelegramConfig | TelegramConfig[];
220
- cloudwatch?: CloudWatchConfig | CloudWatchConfig[];
221
- zohoCliq?: ZohoCliqConfig | ZohoCliqConfig[];
222
- /** Relay transport config — streams logs to a remote server via WebSocket (runs in worker thread) */
223
- relay?: RelayConfig;
224
- /** Enable caller info (file:line) in logs. Pass true for defaults or CallerConfig for options */
225
- caller?: boolean | CallerConfig;
226
- /** Hostname to include in all log entries. Defaults to os.hostname() if not specified */
227
- hostname?: string;
228
- /** Auto-register graceful shutdown handlers. Pass true for defaults or config object */
229
- autoShutdown?: boolean | AutoShutdownConfig;
230
- }
231
- type LoggerContext = Record<string, unknown>;
232
- type LevelOverrideMatch<TContext extends LoggerContext> = Partial<TContext> & {
233
- context?: string;
234
- };
235
- interface LevelOverride<TContext extends LoggerContext> {
236
- match: LevelOverrideMatch<TContext>;
237
- level: LogLevel;
238
- readonly?: boolean;
239
- }
240
- type Meta = object | (() => object);
241
-
242
5
  declare class LoggerStore<TContext extends LoggerContext = LoggerContext> {
243
6
  private storage;
244
7
  getStore(): TContext | undefined;
@@ -387,10 +150,19 @@ interface BaseHttpTransportOptions {
387
150
  * back into the host application.
388
151
  */
389
152
  onError?: (error: Error, droppedMessages: BufferedMessage[]) => void;
153
+ /**
154
+ * If provided, applied to `meta` once per message in `transformMessage`. Used
155
+ * by transports that build payloads via `Object.entries(meta)` iteration
156
+ * (Discord/Telegram/Zoho), where a JSON.stringify replacer can't reach the
157
+ * top-level key. CloudWatch passes `undefined` here and uses a replacer in
158
+ * its own `sendBatch` instead.
159
+ */
160
+ masker?: (value: unknown) => unknown;
390
161
  }
391
162
  declare abstract class BaseHttpTransport {
392
163
  protected buffer: MessageBuffer;
393
164
  private onErrorCallback?;
165
+ private masker?;
394
166
  constructor(opts?: BaseHttpTransportOptions);
395
167
  log(info: Record<string, unknown>, callback: () => void): void;
396
168
  /**
@@ -416,7 +188,7 @@ declare function matchesContext(storeContext: LoggerContext | undefined, loggerC
416
188
  declare class DiscordTransport extends BaseHttpTransport {
417
189
  private config;
418
190
  private requestTimeout;
419
- constructor(config: DiscordConfig);
191
+ constructor(config: DiscordConfig, masker?: (value: unknown) => unknown);
420
192
  protected sendBatch(messages: BufferedMessage[]): Promise<void>;
421
193
  private sendEmbedBatch;
422
194
  private sendMarkdownBatch;
@@ -432,7 +204,7 @@ declare class TelegramTransport extends BaseHttpTransport {
432
204
  private config;
433
205
  private apiUrl;
434
206
  private requestTimeout;
435
- constructor(config: TelegramConfig);
207
+ constructor(config: TelegramConfig, masker?: (value: unknown) => unknown);
436
208
  protected sendBatch(messages: BufferedMessage[]): Promise<void>;
437
209
  private formatBatchMessage;
438
210
  private formatMarkdown;
@@ -450,7 +222,8 @@ declare class CloudWatchTransport extends BaseHttpTransport {
450
222
  private initialized;
451
223
  private initPromise;
452
224
  private resolvedLogStreamName;
453
- constructor(config: CloudWatchConfig, configHostname?: string);
225
+ private maskReplacer;
226
+ constructor(config: CloudWatchConfig, configHostname?: string, maskReplacerFn?: MaskReplacer);
454
227
  protected sendBatch(messages: BufferedMessage[]): Promise<void>;
455
228
  private ensureInitialized;
456
229
  private initialize;
@@ -465,7 +238,7 @@ declare class ZohoCliqTransport extends BaseHttpTransport {
465
238
  private config;
466
239
  private endpoint;
467
240
  private requestTimeout;
468
- constructor(config: ZohoCliqConfig);
241
+ constructor(config: ZohoCliqConfig, masker?: (value: unknown) => unknown);
469
242
  private buildEndpoint;
470
243
  protected sendBatch(messages: BufferedMessage[]): Promise<void>;
471
244
  private formatMessage;
@@ -495,14 +268,6 @@ declare function generateRequestId(options?: RequestIdOptions): string;
495
268
  declare function extractRequestId(headers: Record<string, string | string[] | undefined>): string | undefined;
496
269
  declare function getOrGenerateRequestId(headers: Record<string, string | string[] | undefined>, options?: RequestIdOptions): string;
497
270
 
498
- interface MaskSecretsOptions {
499
- patterns?: string[];
500
- mask?: string;
501
- deep?: boolean;
502
- }
503
- declare function maskSecrets(obj: unknown, options?: MaskSecretsOptions): unknown;
504
- declare function createMasker(options?: MaskSecretsOptions): (obj: unknown) => unknown;
505
-
506
271
  declare function getCallerInfo(config: CallerConfig, additionalOffset?: number): CallerInfo | undefined;
507
272
  declare function formatCallerInfo(info: CallerInfo): string;
508
273
 
@@ -548,6 +313,12 @@ interface HttpErrorData {
548
313
  url?: string;
549
314
  /** HTTP method (GET, POST, etc.) */
550
315
  method?: string;
316
+ /** Request query params */
317
+ params?: unknown;
318
+ /** Request body */
319
+ requestData?: unknown;
320
+ /** Request headers */
321
+ requestHeaders?: unknown;
551
322
  /** Error code (e.g., ECONNREFUSED, ETIMEDOUT) */
552
323
  code?: string;
553
324
  }
@@ -701,6 +472,11 @@ declare const LoggerConfigSchema: z.ZodObject<{
701
472
  caller: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodType<CallerConfig, unknown, z.core.$ZodTypeInternals<CallerConfig, unknown>>]>>;
702
473
  hostname: z.ZodOptional<z.ZodString>;
703
474
  autoShutdown: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodType<AutoShutdownConfig, unknown, z.core.$ZodTypeInternals<AutoShutdownConfig, unknown>>]>>;
475
+ maskSecrets: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
476
+ patterns: z.ZodOptional<z.ZodArray<z.ZodString>>;
477
+ mask: z.ZodOptional<z.ZodString>;
478
+ deep: z.ZodOptional<z.ZodBoolean>;
479
+ }, z.core.$strip>]>>;
704
480
  }, z.core.$strip>;
705
481
  declare function validateConfig(config: unknown): z.infer<typeof LoggerConfigSchema>;
706
482
  declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<{
@@ -765,6 +541,11 @@ declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<{
765
541
  caller?: boolean | CallerConfig | undefined;
766
542
  hostname?: string | undefined;
767
543
  autoShutdown?: boolean | AutoShutdownConfig | undefined;
544
+ maskSecrets?: boolean | {
545
+ patterns?: string[] | undefined;
546
+ mask?: string | undefined;
547
+ deep?: boolean | undefined;
548
+ } | undefined;
768
549
  }>;
769
550
 
770
- export { type AutoShutdownConfig, AutoShutdownConfigSchema, BaseHttpTransport, type BaseHttpTransportOptions, type BufferOptions, type BufferedMessage, type CallerConfig, CallerConfigSchema, type CallerInfo, type CloudWatchConfig, CloudWatchConfigSchema, CloudWatchTransport, type ConsoleConfig, ConsoleConfigSchema, type DiscordConfig, DiscordConfigSchema, DiscordTransport, type FileConfig, FileConfigSchema, type GracefulShutdownOptions, type HttpErrorData, type HttpTransportBaseConfig, HttpTransportBaseConfigSchema, LOG_LEVELS, type LevelConfig, type LevelConfigObject, LevelConfigObjectSchema, LevelConfigSchema, type LevelOverride, type LevelOverrideMatch, type LevelRule, LevelRuleSchema, type LogFormat, LogFormatSchema, type LogLevel, LogLevelSchema, type LogStreamName, LogStreamNameSchema, type LogStreamPattern, type LogStreamPatternConfig, LogStreamPatternConfigSchema, LogStreamPatternSchema, type LogStreamTemplateConfig, LogStreamTemplateConfigSchema, Logger, type LoggerConfig, LoggerConfigSchema, type LoggerContext, LoggerStore, type MaskSecretsOptions, MessageBuffer, type Meta, type RelayConfig, RelayConfigSchema, type RequestIdOptions, type SerializedError, type SingletonLogger, type TelegramConfig, TelegramConfigSchema, TelegramTransport, type TimingResult, type ZohoCliqBotConfig, type ZohoCliqConfig, ZohoCliqConfigSchema, ZohoCliqTransport, assertLogLevel, createMasker, createSingletonLogger, extractRequestId, flattenObject, formatCallerInfo, formatLogfmt, formatLogfmtValue, generateRequestId, getCallerInfo, getOrGenerateRequestId, isValidLogLevel, maskSecrets, matchesContext, measureAsync, measureSync, registerShutdown, safeValidateConfig, serializeError, validateConfig };
551
+ export { AutoShutdownConfig, AutoShutdownConfigSchema, BaseHttpTransport, type BaseHttpTransportOptions, type BufferOptions, type BufferedMessage, CallerConfig, CallerConfigSchema, CallerInfo, CloudWatchConfig, CloudWatchConfigSchema, CloudWatchTransport, ConsoleConfig, ConsoleConfigSchema, DiscordConfig, DiscordConfigSchema, DiscordTransport, FileConfig, FileConfigSchema, type GracefulShutdownOptions, type HttpErrorData, HttpTransportBaseConfig, HttpTransportBaseConfigSchema, LevelConfig, LevelConfigObject, LevelConfigObjectSchema, LevelConfigSchema, LevelOverride, LevelOverrideMatch, LevelRule, LevelRuleSchema, LogFormat, LogFormatSchema, LogLevel, LogLevelSchema, LogStreamName, LogStreamNameSchema, LogStreamPattern, LogStreamPatternConfig, LogStreamPatternConfigSchema, LogStreamPatternSchema, LogStreamTemplateConfig, LogStreamTemplateConfigSchema, Logger, LoggerConfig, LoggerConfigSchema, LoggerContext, LoggerStore, MaskReplacer, MessageBuffer, Meta, RelayConfig, RelayConfigSchema, type RequestIdOptions, type SerializedError, type SingletonLogger, TelegramConfig, TelegramConfigSchema, TelegramTransport, type TimingResult, ZohoCliqConfig, ZohoCliqConfigSchema, ZohoCliqTransport, createSingletonLogger, extractRequestId, flattenObject, formatCallerInfo, formatLogfmt, formatLogfmtValue, generateRequestId, getCallerInfo, getOrGenerateRequestId, matchesContext, measureAsync, measureSync, registerShutdown, safeValidateConfig, serializeError, validateConfig };