@rawnodes/logger 2.8.0 → 2.10.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,222 +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
- interface ConsoleConfig {
24
- format: LogFormat;
25
- level?: LogLevel;
26
- rules?: LevelRule[];
27
- }
28
- interface FileConfig {
29
- format: LogFormat;
30
- level?: LogLevel;
31
- rules?: LevelRule[];
32
- dirname: string;
33
- filename: string;
34
- datePattern?: string;
35
- interval?: string;
36
- zippedArchive?: boolean;
37
- maxSize?: string;
38
- maxFiles?: string;
39
- }
40
- interface HttpTransportBaseConfig {
41
- level?: LogLevel;
42
- rules?: LevelRule[];
43
- batchSize?: number;
44
- flushInterval?: number;
45
- maxRetries?: number;
46
- retryDelay?: number;
47
- /**
48
- * Maximum number of messages the in-memory queue will hold before dropping.
49
- * Provides a hard upper bound on memory usage when a transport is degraded
50
- * or offline — without this, a failing transport + steady log volume grows
51
- * the queue until OOM. Default: unbounded.
52
- *
53
- * Recommended for production: `10_000` — enough to absorb transient blips,
54
- * small enough to avoid runaway memory.
55
- */
56
- maxQueueSize?: number;
57
- /**
58
- * Policy applied when the queue is full.
59
- * - `'drop-oldest'` (default): prefers keeping recent events — during an
60
- * outage old logs are usually stale.
61
- * - `'drop-newest'`: prefers preserving historical context — useful if you
62
- * care more about the events leading up to the outage than the noise
63
- * happening during it.
64
- */
65
- dropPolicy?: 'drop-oldest' | 'drop-newest';
66
- /**
67
- * Called when messages are dropped due to queue overflow. Receives only the
68
- * messages that were discarded. If not provided, drops are silent.
69
- *
70
- * Callback MUST NOT throw; if it does, the exception is swallowed.
71
- */
72
- onDrop?: (droppedMessages: unknown[]) => void;
73
- /**
74
- * Called when a batch fails after all retries and messages are dropped.
75
- * If not provided, the error is logged to stderr.
76
- *
77
- * The callback MUST NOT throw; if it does, the failure is swallowed and a
78
- * stderr fallback is used. This is intentional — a logger must never
79
- * propagate its own transport errors back into the host application.
80
- */
81
- onError?: (error: Error, droppedMessages: unknown[]) => void;
82
- /**
83
- * Timeout in milliseconds for a single outbound HTTP request. Default:
84
- * `10_000`. Applies to Discord/Telegram `fetch`. CloudWatch uses the AWS
85
- * SDK's own timeout configuration.
86
- */
87
- requestTimeout?: number;
88
- }
89
- interface DiscordConfig extends HttpTransportBaseConfig {
90
- webhookUrl: string;
91
- format?: 'embed' | 'markdown';
92
- username?: string;
93
- avatarUrl?: string;
94
- embedColors?: Partial<Record<LogLevel, number>>;
95
- includeTimestamp?: boolean;
96
- includeMeta?: boolean;
97
- maxEmbedFields?: number;
98
- }
99
- interface TelegramConfig extends HttpTransportBaseConfig {
100
- botToken: string;
101
- chatId: string | number;
102
- parseMode?: 'Markdown' | 'MarkdownV2' | 'HTML';
103
- disableNotification?: boolean;
104
- threadId?: number;
105
- replyToMessageId?: number;
106
- }
107
- interface ZohoCliqBotConfig {
108
- /** Bot display name (shown in the channel). */
109
- name: string;
110
- /** Optional bot avatar URL. */
111
- image?: string;
112
- }
113
- interface ZohoCliqConfig extends HttpTransportBaseConfig {
114
- /**
115
- * Incoming webhook URL. If provided, `companyId`/`channel`/`region` are
116
- * ignored and this URL is used as-is (with `zapikey` appended as query).
117
- */
118
- webhookUrl?: string;
119
- /** Zoho Cliq company/org ID. Required unless `webhookUrl` is set. */
120
- companyId?: string;
121
- /** Target channel name (the `channelsbyname` API segment). Required unless `webhookUrl` is set. */
122
- channel?: string;
123
- /** Zoho region/TLD: 'eu' | 'com' | 'in' | etc. Default: 'eu'. */
124
- region?: string;
125
- /** Zoho API key (zapikey). Required. */
126
- apiKey: string;
127
- /** If true (default), message is posted as a broadcast so all members are notified. */
128
- broadcast?: boolean;
129
- /** Post as a custom bot instead of the default user. */
130
- bot?: ZohoCliqBotConfig;
131
- /** Include ISO timestamp in each formatted message. Default: true. */
132
- includeTimestamp?: boolean;
133
- /** Include meta as a fenced code block. Default: true. */
134
- includeMeta?: boolean;
135
- }
136
- type LogStreamPattern = 'hostname' | 'hostname-date' | 'hostname-uuid' | 'date' | 'uuid';
137
- interface LogStreamPatternConfig {
138
- pattern: LogStreamPattern;
139
- }
140
- interface LogStreamTemplateConfig {
141
- /** Custom template with variables: {hostname}, {date}, {datetime}, {uuid}, {pid}, {env} */
142
- template: string;
143
- }
144
- type LogStreamName = string | LogStreamPatternConfig | LogStreamTemplateConfig;
145
- interface RelayConfig {
146
- /** URL of the relay API (e.g., https://relay.example.com) */
147
- apiUrl: string;
148
- /** Authentication token for the relay server */
149
- token: string;
150
- /** Polling interval in ms (default: 30000) */
151
- pollInterval?: number;
152
- /** Ring buffer capacity - max logs held during reconnect (default: 1000) */
153
- bufferSize?: number;
154
- /** WebSocket reconnect base delay in ms (default: 1000) */
155
- reconnectDelay?: number;
156
- /** Max reconnect delay in ms (default: 30000) */
157
- maxReconnectDelay?: number;
158
- }
159
- interface CloudWatchConfig extends HttpTransportBaseConfig {
160
- logGroupName: string;
161
- /** Log stream name - string, pattern config, or template config. Defaults to hostname pattern */
162
- logStreamName?: LogStreamName;
163
- region: string;
164
- accessKeyId: string;
165
- secretAccessKey: string;
166
- createLogGroup?: boolean;
167
- createLogStream?: boolean;
168
- }
169
- interface LevelConfigObject {
170
- default: LogLevel;
171
- rules?: LevelRule[];
172
- }
173
- type LevelConfig = LogLevel | LevelConfigObject;
174
- interface CallerConfig {
175
- /** Stack depth to capture (default: 1). Higher values trace further up the call stack */
176
- depth?: number;
177
- /** Include full file path (default: false). If false, shows relative or basename only */
178
- fullPath?: boolean;
179
- }
180
- interface CallerInfo {
181
- file: string;
182
- line: number;
183
- column?: number;
184
- function?: string;
185
- }
186
- interface AutoShutdownConfig {
187
- /** Timeout in ms before forcing exit (default: 5000) */
188
- timeout?: number;
189
- /** Custom signals to handle (default: ['SIGTERM', 'SIGINT']) */
190
- signals?: NodeJS.Signals[];
191
- }
192
- interface LoggerConfig {
193
- level: LevelConfig;
194
- console: ConsoleConfig;
195
- file?: FileConfig;
196
- discord?: DiscordConfig | DiscordConfig[];
197
- telegram?: TelegramConfig | TelegramConfig[];
198
- cloudwatch?: CloudWatchConfig | CloudWatchConfig[];
199
- zohoCliq?: ZohoCliqConfig | ZohoCliqConfig[];
200
- /** Relay transport config — streams logs to a remote server via WebSocket (runs in worker thread) */
201
- relay?: RelayConfig;
202
- /** Enable caller info (file:line) in logs. Pass true for defaults or CallerConfig for options */
203
- caller?: boolean | CallerConfig;
204
- /** Hostname to include in all log entries. Defaults to os.hostname() if not specified */
205
- hostname?: string;
206
- /** Auto-register graceful shutdown handlers. Pass true for defaults or config object */
207
- autoShutdown?: boolean | AutoShutdownConfig;
208
- }
209
- type LoggerContext = Record<string, unknown>;
210
- type LevelOverrideMatch<TContext extends LoggerContext> = Partial<TContext> & {
211
- context?: string;
212
- };
213
- interface LevelOverride<TContext extends LoggerContext> {
214
- match: LevelOverrideMatch<TContext>;
215
- level: LogLevel;
216
- readonly?: boolean;
217
- }
218
- type Meta = object | (() => object);
219
-
220
5
  declare class LoggerStore<TContext extends LoggerContext = LoggerContext> {
221
6
  private storage;
222
7
  getStore(): TContext | undefined;
@@ -365,10 +150,19 @@ interface BaseHttpTransportOptions {
365
150
  * back into the host application.
366
151
  */
367
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;
368
161
  }
369
162
  declare abstract class BaseHttpTransport {
370
163
  protected buffer: MessageBuffer;
371
164
  private onErrorCallback?;
165
+ private masker?;
372
166
  constructor(opts?: BaseHttpTransportOptions);
373
167
  log(info: Record<string, unknown>, callback: () => void): void;
374
168
  /**
@@ -394,7 +188,7 @@ declare function matchesContext(storeContext: LoggerContext | undefined, loggerC
394
188
  declare class DiscordTransport extends BaseHttpTransport {
395
189
  private config;
396
190
  private requestTimeout;
397
- constructor(config: DiscordConfig);
191
+ constructor(config: DiscordConfig, masker?: (value: unknown) => unknown);
398
192
  protected sendBatch(messages: BufferedMessage[]): Promise<void>;
399
193
  private sendEmbedBatch;
400
194
  private sendMarkdownBatch;
@@ -410,7 +204,7 @@ declare class TelegramTransport extends BaseHttpTransport {
410
204
  private config;
411
205
  private apiUrl;
412
206
  private requestTimeout;
413
- constructor(config: TelegramConfig);
207
+ constructor(config: TelegramConfig, masker?: (value: unknown) => unknown);
414
208
  protected sendBatch(messages: BufferedMessage[]): Promise<void>;
415
209
  private formatBatchMessage;
416
210
  private formatMarkdown;
@@ -428,7 +222,8 @@ declare class CloudWatchTransport extends BaseHttpTransport {
428
222
  private initialized;
429
223
  private initPromise;
430
224
  private resolvedLogStreamName;
431
- constructor(config: CloudWatchConfig, configHostname?: string);
225
+ private maskReplacer;
226
+ constructor(config: CloudWatchConfig, configHostname?: string, maskReplacerFn?: MaskReplacer);
432
227
  protected sendBatch(messages: BufferedMessage[]): Promise<void>;
433
228
  private ensureInitialized;
434
229
  private initialize;
@@ -443,7 +238,7 @@ declare class ZohoCliqTransport extends BaseHttpTransport {
443
238
  private config;
444
239
  private endpoint;
445
240
  private requestTimeout;
446
- constructor(config: ZohoCliqConfig);
241
+ constructor(config: ZohoCliqConfig, masker?: (value: unknown) => unknown);
447
242
  private buildEndpoint;
448
243
  protected sendBatch(messages: BufferedMessage[]): Promise<void>;
449
244
  private formatMessage;
@@ -473,14 +268,6 @@ declare function generateRequestId(options?: RequestIdOptions): string;
473
268
  declare function extractRequestId(headers: Record<string, string | string[] | undefined>): string | undefined;
474
269
  declare function getOrGenerateRequestId(headers: Record<string, string | string[] | undefined>, options?: RequestIdOptions): string;
475
270
 
476
- interface MaskSecretsOptions {
477
- patterns?: string[];
478
- mask?: string;
479
- deep?: boolean;
480
- }
481
- declare function maskSecrets(obj: unknown, options?: MaskSecretsOptions): unknown;
482
- declare function createMasker(options?: MaskSecretsOptions): (obj: unknown) => unknown;
483
-
484
271
  declare function getCallerInfo(config: CallerConfig, additionalOffset?: number): CallerInfo | undefined;
485
272
  declare function formatCallerInfo(info: CallerInfo): string;
486
273
 
@@ -580,6 +367,7 @@ declare const CloudWatchConfigSchema: z.ZodType<CloudWatchConfig>;
580
367
  declare const ZohoCliqConfigSchema: z.ZodObject<{
581
368
  level: z.ZodOptional<z.ZodType<"off" | "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly", unknown, z.core.$ZodTypeInternals<"off" | "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly", unknown>>>;
582
369
  rules: z.ZodOptional<z.ZodArray<z.ZodType<LevelRule, unknown, z.core.$ZodTypeInternals<LevelRule, unknown>>>>;
370
+ respectRuntimeOverrides: z.ZodOptional<z.ZodBoolean>;
583
371
  batchSize: z.ZodOptional<z.ZodNumber>;
584
372
  flushInterval: z.ZodOptional<z.ZodNumber>;
585
373
  maxRetries: z.ZodOptional<z.ZodNumber>;
@@ -620,6 +408,7 @@ declare const LoggerConfigSchema: z.ZodObject<{
620
408
  zohoCliq: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
621
409
  level: z.ZodOptional<z.ZodType<"off" | "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly", unknown, z.core.$ZodTypeInternals<"off" | "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly", unknown>>>;
622
410
  rules: z.ZodOptional<z.ZodArray<z.ZodType<LevelRule, unknown, z.core.$ZodTypeInternals<LevelRule, unknown>>>>;
411
+ respectRuntimeOverrides: z.ZodOptional<z.ZodBoolean>;
623
412
  batchSize: z.ZodOptional<z.ZodNumber>;
624
413
  flushInterval: z.ZodOptional<z.ZodNumber>;
625
414
  maxRetries: z.ZodOptional<z.ZodNumber>;
@@ -647,6 +436,7 @@ declare const LoggerConfigSchema: z.ZodObject<{
647
436
  }, z.core.$strip>, z.ZodArray<z.ZodObject<{
648
437
  level: z.ZodOptional<z.ZodType<"off" | "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly", unknown, z.core.$ZodTypeInternals<"off" | "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly", unknown>>>;
649
438
  rules: z.ZodOptional<z.ZodArray<z.ZodType<LevelRule, unknown, z.core.$ZodTypeInternals<LevelRule, unknown>>>>;
439
+ respectRuntimeOverrides: z.ZodOptional<z.ZodBoolean>;
650
440
  batchSize: z.ZodOptional<z.ZodNumber>;
651
441
  flushInterval: z.ZodOptional<z.ZodNumber>;
652
442
  maxRetries: z.ZodOptional<z.ZodNumber>;
@@ -676,6 +466,11 @@ declare const LoggerConfigSchema: z.ZodObject<{
676
466
  caller: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodType<CallerConfig, unknown, z.core.$ZodTypeInternals<CallerConfig, unknown>>]>>;
677
467
  hostname: z.ZodOptional<z.ZodString>;
678
468
  autoShutdown: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodType<AutoShutdownConfig, unknown, z.core.$ZodTypeInternals<AutoShutdownConfig, unknown>>]>>;
469
+ maskSecrets: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
470
+ patterns: z.ZodOptional<z.ZodArray<z.ZodString>>;
471
+ mask: z.ZodOptional<z.ZodString>;
472
+ deep: z.ZodOptional<z.ZodBoolean>;
473
+ }, z.core.$strip>]>>;
679
474
  }, z.core.$strip>;
680
475
  declare function validateConfig(config: unknown): z.infer<typeof LoggerConfigSchema>;
681
476
  declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<{
@@ -691,6 +486,7 @@ declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<{
691
486
  apiKey: string;
692
487
  level?: "off" | "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly" | undefined;
693
488
  rules?: LevelRule[] | undefined;
489
+ respectRuntimeOverrides?: boolean | undefined;
694
490
  batchSize?: number | undefined;
695
491
  flushInterval?: number | undefined;
696
492
  maxRetries?: number | undefined;
@@ -715,6 +511,7 @@ declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<{
715
511
  apiKey: string;
716
512
  level?: "off" | "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly" | undefined;
717
513
  rules?: LevelRule[] | undefined;
514
+ respectRuntimeOverrides?: boolean | undefined;
718
515
  batchSize?: number | undefined;
719
516
  flushInterval?: number | undefined;
720
517
  maxRetries?: number | undefined;
@@ -738,6 +535,11 @@ declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<{
738
535
  caller?: boolean | CallerConfig | undefined;
739
536
  hostname?: string | undefined;
740
537
  autoShutdown?: boolean | AutoShutdownConfig | undefined;
538
+ maskSecrets?: boolean | {
539
+ patterns?: string[] | undefined;
540
+ mask?: string | undefined;
541
+ deep?: boolean | undefined;
542
+ } | undefined;
741
543
  }>;
742
544
 
743
- 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 };
545
+ 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 };