@rawnodes/logger 2.7.2 → 2.9.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
@@ -136,16 +136,57 @@ This is useful for sending only critical errors to alerting systems while keepin
136
136
 
137
137
  #### Level precedence
138
138
 
139
- When deciding whether to emit a log entry, the following order applies **most specific wins**:
139
+ Each transport decides on its own whether to emit a given log entry. The precedence depends on whether the transport **respects runtime overrides** (see the next section):
140
140
 
141
- 1. **Global override** from `setLevelOverride(...)` or the top-level `level.rules` array
141
+ **When respecting overrides** (observability transports console/file/cloudwatch/relay by default):
142
+
143
+ 1. **Runtime override** from `setLevelOverride(...)` or the top-level `level.rules` array
142
144
  2. **Per-transport rule** (a matching entry in `console.rules` / `file.rules` / etc.)
143
145
  3. **Per-transport level** (`console.level`, `file.level`, …)
144
146
  4. **Global default level** (`level` or `level.default`)
145
147
 
146
- Practically: a matching `setLevelOverride({ userId: 123 }, 'debug')` will surface debug logs to **every** transport, even one whose own `level` is set to `info`. This is intentional dynamic overrides are for targeted troubleshooting, and they wouldn't be useful if a downstream transport could silently swallow the messages they just enabled.
148
+ **When ignoring overrides** (alert transportsdiscord/telegram/zohoCliq by default):
149
+
150
+ 1. **Per-transport rule**
151
+ 2. **Per-transport level**
152
+ 3. **Global default level**
153
+
154
+ Practically: a matching `setLevelOverride({ userId: 123 }, 'debug')` will surface debug logs to **viewing** transports (console/cloudwatch/file), even if their own `level` is set to `info`. But the same override will **not** leak through notification channels (discord/telegram/zohoCliq) unless you explicitly opt them in via `respectRuntimeOverrides: true`.
155
+
156
+ #### Transport roles (`respectRuntimeOverrides`)
157
+
158
+ Every transport config accepts an optional `respectRuntimeOverrides?: boolean` flag. Defaults:
147
159
 
148
- If you need a transport to stay narrow while overrides are active, use `rules` on that transport (level 2), not the plain `level` field.
160
+ | Transport | Default | Role |
161
+ |--------------|---------|---------------|
162
+ | `console` | `true` | observability |
163
+ | `file` | `true` | observability |
164
+ | `cloudwatch` | `true` | observability |
165
+ | `relay` | `true` | observability |
166
+ | `discord` | `false` | alert |
167
+ | `telegram` | `false` | alert |
168
+ | `zohoCliq` | `false` | alert |
169
+
170
+ The defaults reflect typical usage — console/file/cloudwatch are where operators look for logs during troubleshooting, while discord/telegram/zohoCliq are user-facing notification channels that should not get flooded by ad-hoc debug overrides. Override the default per-transport when needed:
171
+
172
+ ```typescript
173
+ const logger = Logger.create({
174
+ level: 'info',
175
+ console: { format: 'plain' },
176
+ telegram: {
177
+ botToken: '...',
178
+ chatId: '...',
179
+ level: 'warn',
180
+ respectRuntimeOverrides: true, // let overrides through (rare)
181
+ },
182
+ cloudwatch: {
183
+ logGroupName: '...',
184
+ level: 'info',
185
+ respectRuntimeOverrides: false, // strict gate even under troubleshooting (also rare)
186
+ region: '...', accessKeyId: '...', secretAccessKey: '...',
187
+ },
188
+ });
189
+ ```
149
190
 
150
191
  ### Per-Transport Rules
151
192
 
package/dist/index.d.mts CHANGED
@@ -20,15 +20,34 @@ interface LevelRule {
20
20
  };
21
21
  level: LogLevel;
22
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;
23
40
  interface ConsoleConfig {
24
41
  format: LogFormat;
25
42
  level?: LogLevel;
26
43
  rules?: LevelRule[];
44
+ respectRuntimeOverrides?: RespectRuntimeOverrides;
27
45
  }
28
46
  interface FileConfig {
29
47
  format: LogFormat;
30
48
  level?: LogLevel;
31
49
  rules?: LevelRule[];
50
+ respectRuntimeOverrides?: RespectRuntimeOverrides;
32
51
  dirname: string;
33
52
  filename: string;
34
53
  datePattern?: string;
@@ -40,6 +59,7 @@ interface FileConfig {
40
59
  interface HttpTransportBaseConfig {
41
60
  level?: LogLevel;
42
61
  rules?: LevelRule[];
62
+ respectRuntimeOverrides?: RespectRuntimeOverrides;
43
63
  batchSize?: number;
44
64
  flushInterval?: number;
45
65
  maxRetries?: number;
@@ -104,6 +124,35 @@ interface TelegramConfig extends HttpTransportBaseConfig {
104
124
  threadId?: number;
105
125
  replyToMessageId?: number;
106
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
+ }
107
156
  type LogStreamPattern = 'hostname' | 'hostname-date' | 'hostname-uuid' | 'date' | 'uuid';
108
157
  interface LogStreamPatternConfig {
109
158
  pattern: LogStreamPattern;
@@ -126,6 +175,8 @@ interface RelayConfig {
126
175
  reconnectDelay?: number;
127
176
  /** Max reconnect delay in ms (default: 30000) */
128
177
  maxReconnectDelay?: number;
178
+ /** See RespectRuntimeOverrides. Default: true (relay is an observability transport). */
179
+ respectRuntimeOverrides?: RespectRuntimeOverrides;
129
180
  }
130
181
  interface CloudWatchConfig extends HttpTransportBaseConfig {
131
182
  logGroupName: string;
@@ -167,6 +218,7 @@ interface LoggerConfig {
167
218
  discord?: DiscordConfig | DiscordConfig[];
168
219
  telegram?: TelegramConfig | TelegramConfig[];
169
220
  cloudwatch?: CloudWatchConfig | CloudWatchConfig[];
221
+ zohoCliq?: ZohoCliqConfig | ZohoCliqConfig[];
170
222
  /** Relay transport config — streams logs to a remote server via WebSocket (runs in worker thread) */
171
223
  relay?: RelayConfig;
172
224
  /** Enable caller info (file:line) in logs. Pass true for defaults or CallerConfig for options */
@@ -409,6 +461,18 @@ declare class CloudWatchTransport extends BaseHttpTransport {
409
461
  private isInvalidSequenceTokenError;
410
462
  }
411
463
 
464
+ declare class ZohoCliqTransport extends BaseHttpTransport {
465
+ private config;
466
+ private endpoint;
467
+ private requestTimeout;
468
+ constructor(config: ZohoCliqConfig);
469
+ private buildEndpoint;
470
+ protected sendBatch(messages: BufferedMessage[]): Promise<void>;
471
+ private formatMessage;
472
+ private splitContent;
473
+ private post;
474
+ }
475
+
412
476
  interface TimingResult {
413
477
  label: string;
414
478
  durationMs: number;
@@ -535,6 +599,36 @@ declare const LogStreamPatternConfigSchema: z.ZodType<LogStreamPatternConfig>;
535
599
  declare const LogStreamTemplateConfigSchema: z.ZodType<LogStreamTemplateConfig>;
536
600
  declare const LogStreamNameSchema: z.ZodType<LogStreamName>;
537
601
  declare const CloudWatchConfigSchema: z.ZodType<CloudWatchConfig>;
602
+ declare const ZohoCliqConfigSchema: z.ZodObject<{
603
+ 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>>>;
604
+ rules: z.ZodOptional<z.ZodArray<z.ZodType<LevelRule, unknown, z.core.$ZodTypeInternals<LevelRule, unknown>>>>;
605
+ respectRuntimeOverrides: z.ZodOptional<z.ZodBoolean>;
606
+ batchSize: z.ZodOptional<z.ZodNumber>;
607
+ flushInterval: z.ZodOptional<z.ZodNumber>;
608
+ maxRetries: z.ZodOptional<z.ZodNumber>;
609
+ retryDelay: z.ZodOptional<z.ZodNumber>;
610
+ onError: z.ZodType<HttpTransportBaseConfig["onError"]>;
611
+ onDrop: z.ZodType<HttpTransportBaseConfig["onDrop"]>;
612
+ maxQueueSize: z.ZodOptional<z.ZodNumber>;
613
+ dropPolicy: z.ZodOptional<z.ZodEnum<{
614
+ "drop-oldest": "drop-oldest";
615
+ "drop-newest": "drop-newest";
616
+ }>>;
617
+ requestTimeout: z.ZodOptional<z.ZodNumber>;
618
+ webhookUrl: z.ZodOptional<z.ZodString>;
619
+ companyId: z.ZodOptional<z.ZodString>;
620
+ channel: z.ZodOptional<z.ZodString>;
621
+ region: z.ZodOptional<z.ZodString>;
622
+ apiKey: z.ZodString;
623
+ broadcast: z.ZodOptional<z.ZodBoolean>;
624
+ bot: z.ZodOptional<z.ZodObject<{
625
+ name: z.ZodString;
626
+ image: z.ZodOptional<z.ZodString>;
627
+ }, z.core.$strip>>;
628
+ includeTimestamp: z.ZodOptional<z.ZodBoolean>;
629
+ includeMeta: z.ZodOptional<z.ZodBoolean>;
630
+ }, z.core.$strip>;
631
+ declare const RelayConfigSchema: z.ZodType<RelayConfig>;
538
632
  declare const LevelConfigObjectSchema: z.ZodType<LevelConfigObject>;
539
633
  declare const LevelConfigSchema: z.ZodType<LevelConfig>;
540
634
  declare const CallerConfigSchema: z.ZodType<CallerConfig>;
@@ -546,6 +640,63 @@ declare const LoggerConfigSchema: z.ZodObject<{
546
640
  discord: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<DiscordConfig, unknown, z.core.$ZodTypeInternals<DiscordConfig, unknown>>, z.ZodArray<z.ZodType<DiscordConfig, unknown, z.core.$ZodTypeInternals<DiscordConfig, unknown>>>]>>;
547
641
  telegram: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<TelegramConfig, unknown, z.core.$ZodTypeInternals<TelegramConfig, unknown>>, z.ZodArray<z.ZodType<TelegramConfig, unknown, z.core.$ZodTypeInternals<TelegramConfig, unknown>>>]>>;
548
642
  cloudwatch: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<CloudWatchConfig, unknown, z.core.$ZodTypeInternals<CloudWatchConfig, unknown>>, z.ZodArray<z.ZodType<CloudWatchConfig, unknown, z.core.$ZodTypeInternals<CloudWatchConfig, unknown>>>]>>;
643
+ zohoCliq: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
644
+ 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>>>;
645
+ rules: z.ZodOptional<z.ZodArray<z.ZodType<LevelRule, unknown, z.core.$ZodTypeInternals<LevelRule, unknown>>>>;
646
+ respectRuntimeOverrides: z.ZodOptional<z.ZodBoolean>;
647
+ batchSize: z.ZodOptional<z.ZodNumber>;
648
+ flushInterval: z.ZodOptional<z.ZodNumber>;
649
+ maxRetries: z.ZodOptional<z.ZodNumber>;
650
+ retryDelay: z.ZodOptional<z.ZodNumber>;
651
+ onError: z.ZodType<HttpTransportBaseConfig["onError"]>;
652
+ onDrop: z.ZodType<HttpTransportBaseConfig["onDrop"]>;
653
+ maxQueueSize: z.ZodOptional<z.ZodNumber>;
654
+ dropPolicy: z.ZodOptional<z.ZodEnum<{
655
+ "drop-oldest": "drop-oldest";
656
+ "drop-newest": "drop-newest";
657
+ }>>;
658
+ requestTimeout: z.ZodOptional<z.ZodNumber>;
659
+ webhookUrl: z.ZodOptional<z.ZodString>;
660
+ companyId: z.ZodOptional<z.ZodString>;
661
+ channel: z.ZodOptional<z.ZodString>;
662
+ region: z.ZodOptional<z.ZodString>;
663
+ apiKey: z.ZodString;
664
+ broadcast: z.ZodOptional<z.ZodBoolean>;
665
+ bot: z.ZodOptional<z.ZodObject<{
666
+ name: z.ZodString;
667
+ image: z.ZodOptional<z.ZodString>;
668
+ }, z.core.$strip>>;
669
+ includeTimestamp: z.ZodOptional<z.ZodBoolean>;
670
+ includeMeta: z.ZodOptional<z.ZodBoolean>;
671
+ }, z.core.$strip>, z.ZodArray<z.ZodObject<{
672
+ 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>>>;
673
+ rules: z.ZodOptional<z.ZodArray<z.ZodType<LevelRule, unknown, z.core.$ZodTypeInternals<LevelRule, unknown>>>>;
674
+ respectRuntimeOverrides: z.ZodOptional<z.ZodBoolean>;
675
+ batchSize: z.ZodOptional<z.ZodNumber>;
676
+ flushInterval: z.ZodOptional<z.ZodNumber>;
677
+ maxRetries: z.ZodOptional<z.ZodNumber>;
678
+ retryDelay: z.ZodOptional<z.ZodNumber>;
679
+ onError: z.ZodType<HttpTransportBaseConfig["onError"]>;
680
+ onDrop: z.ZodType<HttpTransportBaseConfig["onDrop"]>;
681
+ maxQueueSize: z.ZodOptional<z.ZodNumber>;
682
+ dropPolicy: z.ZodOptional<z.ZodEnum<{
683
+ "drop-oldest": "drop-oldest";
684
+ "drop-newest": "drop-newest";
685
+ }>>;
686
+ requestTimeout: z.ZodOptional<z.ZodNumber>;
687
+ webhookUrl: z.ZodOptional<z.ZodString>;
688
+ companyId: z.ZodOptional<z.ZodString>;
689
+ channel: z.ZodOptional<z.ZodString>;
690
+ region: z.ZodOptional<z.ZodString>;
691
+ apiKey: z.ZodString;
692
+ broadcast: z.ZodOptional<z.ZodBoolean>;
693
+ bot: z.ZodOptional<z.ZodObject<{
694
+ name: z.ZodString;
695
+ image: z.ZodOptional<z.ZodString>;
696
+ }, z.core.$strip>>;
697
+ includeTimestamp: z.ZodOptional<z.ZodBoolean>;
698
+ includeMeta: z.ZodOptional<z.ZodBoolean>;
699
+ }, z.core.$strip>>]>>;
549
700
  relay: z.ZodOptional<z.ZodType<RelayConfig, unknown, z.core.$ZodTypeInternals<RelayConfig, unknown>>>;
550
701
  caller: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodType<CallerConfig, unknown, z.core.$ZodTypeInternals<CallerConfig, unknown>>]>>;
551
702
  hostname: z.ZodOptional<z.ZodString>;
@@ -559,10 +710,61 @@ declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<{
559
710
  discord?: DiscordConfig | DiscordConfig[] | undefined;
560
711
  telegram?: TelegramConfig | TelegramConfig[] | undefined;
561
712
  cloudwatch?: CloudWatchConfig | CloudWatchConfig[] | undefined;
713
+ zohoCliq?: {
714
+ onError: ((error: Error, droppedMessages: unknown[]) => void) | undefined;
715
+ onDrop: ((droppedMessages: unknown[]) => void) | undefined;
716
+ apiKey: string;
717
+ level?: "off" | "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly" | undefined;
718
+ rules?: LevelRule[] | undefined;
719
+ respectRuntimeOverrides?: boolean | undefined;
720
+ batchSize?: number | undefined;
721
+ flushInterval?: number | undefined;
722
+ maxRetries?: number | undefined;
723
+ retryDelay?: number | undefined;
724
+ maxQueueSize?: number | undefined;
725
+ dropPolicy?: "drop-oldest" | "drop-newest" | undefined;
726
+ requestTimeout?: number | undefined;
727
+ webhookUrl?: string | undefined;
728
+ companyId?: string | undefined;
729
+ channel?: string | undefined;
730
+ region?: string | undefined;
731
+ broadcast?: boolean | undefined;
732
+ bot?: {
733
+ name: string;
734
+ image?: string | undefined;
735
+ } | undefined;
736
+ includeTimestamp?: boolean | undefined;
737
+ includeMeta?: boolean | undefined;
738
+ } | {
739
+ onError: ((error: Error, droppedMessages: unknown[]) => void) | undefined;
740
+ onDrop: ((droppedMessages: unknown[]) => void) | undefined;
741
+ apiKey: string;
742
+ level?: "off" | "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly" | undefined;
743
+ rules?: LevelRule[] | undefined;
744
+ respectRuntimeOverrides?: boolean | undefined;
745
+ batchSize?: number | undefined;
746
+ flushInterval?: number | undefined;
747
+ maxRetries?: number | undefined;
748
+ retryDelay?: number | undefined;
749
+ maxQueueSize?: number | undefined;
750
+ dropPolicy?: "drop-oldest" | "drop-newest" | undefined;
751
+ requestTimeout?: number | undefined;
752
+ webhookUrl?: string | undefined;
753
+ companyId?: string | undefined;
754
+ channel?: string | undefined;
755
+ region?: string | undefined;
756
+ broadcast?: boolean | undefined;
757
+ bot?: {
758
+ name: string;
759
+ image?: string | undefined;
760
+ } | undefined;
761
+ includeTimestamp?: boolean | undefined;
762
+ includeMeta?: boolean | undefined;
763
+ }[] | undefined;
562
764
  relay?: RelayConfig | undefined;
563
765
  caller?: boolean | CallerConfig | undefined;
564
766
  hostname?: string | undefined;
565
767
  autoShutdown?: boolean | AutoShutdownConfig | undefined;
566
768
  }>;
567
769
 
568
- 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 RequestIdOptions, type SerializedError, type SingletonLogger, type TelegramConfig, TelegramConfigSchema, TelegramTransport, type TimingResult, assertLogLevel, createMasker, createSingletonLogger, extractRequestId, flattenObject, formatCallerInfo, formatLogfmt, formatLogfmtValue, generateRequestId, getCallerInfo, getOrGenerateRequestId, isValidLogLevel, maskSecrets, matchesContext, measureAsync, measureSync, registerShutdown, safeValidateConfig, serializeError, validateConfig };
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 };
package/dist/index.d.ts CHANGED
@@ -20,15 +20,34 @@ interface LevelRule {
20
20
  };
21
21
  level: LogLevel;
22
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;
23
40
  interface ConsoleConfig {
24
41
  format: LogFormat;
25
42
  level?: LogLevel;
26
43
  rules?: LevelRule[];
44
+ respectRuntimeOverrides?: RespectRuntimeOverrides;
27
45
  }
28
46
  interface FileConfig {
29
47
  format: LogFormat;
30
48
  level?: LogLevel;
31
49
  rules?: LevelRule[];
50
+ respectRuntimeOverrides?: RespectRuntimeOverrides;
32
51
  dirname: string;
33
52
  filename: string;
34
53
  datePattern?: string;
@@ -40,6 +59,7 @@ interface FileConfig {
40
59
  interface HttpTransportBaseConfig {
41
60
  level?: LogLevel;
42
61
  rules?: LevelRule[];
62
+ respectRuntimeOverrides?: RespectRuntimeOverrides;
43
63
  batchSize?: number;
44
64
  flushInterval?: number;
45
65
  maxRetries?: number;
@@ -104,6 +124,35 @@ interface TelegramConfig extends HttpTransportBaseConfig {
104
124
  threadId?: number;
105
125
  replyToMessageId?: number;
106
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
+ }
107
156
  type LogStreamPattern = 'hostname' | 'hostname-date' | 'hostname-uuid' | 'date' | 'uuid';
108
157
  interface LogStreamPatternConfig {
109
158
  pattern: LogStreamPattern;
@@ -126,6 +175,8 @@ interface RelayConfig {
126
175
  reconnectDelay?: number;
127
176
  /** Max reconnect delay in ms (default: 30000) */
128
177
  maxReconnectDelay?: number;
178
+ /** See RespectRuntimeOverrides. Default: true (relay is an observability transport). */
179
+ respectRuntimeOverrides?: RespectRuntimeOverrides;
129
180
  }
130
181
  interface CloudWatchConfig extends HttpTransportBaseConfig {
131
182
  logGroupName: string;
@@ -167,6 +218,7 @@ interface LoggerConfig {
167
218
  discord?: DiscordConfig | DiscordConfig[];
168
219
  telegram?: TelegramConfig | TelegramConfig[];
169
220
  cloudwatch?: CloudWatchConfig | CloudWatchConfig[];
221
+ zohoCliq?: ZohoCliqConfig | ZohoCliqConfig[];
170
222
  /** Relay transport config — streams logs to a remote server via WebSocket (runs in worker thread) */
171
223
  relay?: RelayConfig;
172
224
  /** Enable caller info (file:line) in logs. Pass true for defaults or CallerConfig for options */
@@ -409,6 +461,18 @@ declare class CloudWatchTransport extends BaseHttpTransport {
409
461
  private isInvalidSequenceTokenError;
410
462
  }
411
463
 
464
+ declare class ZohoCliqTransport extends BaseHttpTransport {
465
+ private config;
466
+ private endpoint;
467
+ private requestTimeout;
468
+ constructor(config: ZohoCliqConfig);
469
+ private buildEndpoint;
470
+ protected sendBatch(messages: BufferedMessage[]): Promise<void>;
471
+ private formatMessage;
472
+ private splitContent;
473
+ private post;
474
+ }
475
+
412
476
  interface TimingResult {
413
477
  label: string;
414
478
  durationMs: number;
@@ -535,6 +599,36 @@ declare const LogStreamPatternConfigSchema: z.ZodType<LogStreamPatternConfig>;
535
599
  declare const LogStreamTemplateConfigSchema: z.ZodType<LogStreamTemplateConfig>;
536
600
  declare const LogStreamNameSchema: z.ZodType<LogStreamName>;
537
601
  declare const CloudWatchConfigSchema: z.ZodType<CloudWatchConfig>;
602
+ declare const ZohoCliqConfigSchema: z.ZodObject<{
603
+ 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>>>;
604
+ rules: z.ZodOptional<z.ZodArray<z.ZodType<LevelRule, unknown, z.core.$ZodTypeInternals<LevelRule, unknown>>>>;
605
+ respectRuntimeOverrides: z.ZodOptional<z.ZodBoolean>;
606
+ batchSize: z.ZodOptional<z.ZodNumber>;
607
+ flushInterval: z.ZodOptional<z.ZodNumber>;
608
+ maxRetries: z.ZodOptional<z.ZodNumber>;
609
+ retryDelay: z.ZodOptional<z.ZodNumber>;
610
+ onError: z.ZodType<HttpTransportBaseConfig["onError"]>;
611
+ onDrop: z.ZodType<HttpTransportBaseConfig["onDrop"]>;
612
+ maxQueueSize: z.ZodOptional<z.ZodNumber>;
613
+ dropPolicy: z.ZodOptional<z.ZodEnum<{
614
+ "drop-oldest": "drop-oldest";
615
+ "drop-newest": "drop-newest";
616
+ }>>;
617
+ requestTimeout: z.ZodOptional<z.ZodNumber>;
618
+ webhookUrl: z.ZodOptional<z.ZodString>;
619
+ companyId: z.ZodOptional<z.ZodString>;
620
+ channel: z.ZodOptional<z.ZodString>;
621
+ region: z.ZodOptional<z.ZodString>;
622
+ apiKey: z.ZodString;
623
+ broadcast: z.ZodOptional<z.ZodBoolean>;
624
+ bot: z.ZodOptional<z.ZodObject<{
625
+ name: z.ZodString;
626
+ image: z.ZodOptional<z.ZodString>;
627
+ }, z.core.$strip>>;
628
+ includeTimestamp: z.ZodOptional<z.ZodBoolean>;
629
+ includeMeta: z.ZodOptional<z.ZodBoolean>;
630
+ }, z.core.$strip>;
631
+ declare const RelayConfigSchema: z.ZodType<RelayConfig>;
538
632
  declare const LevelConfigObjectSchema: z.ZodType<LevelConfigObject>;
539
633
  declare const LevelConfigSchema: z.ZodType<LevelConfig>;
540
634
  declare const CallerConfigSchema: z.ZodType<CallerConfig>;
@@ -546,6 +640,63 @@ declare const LoggerConfigSchema: z.ZodObject<{
546
640
  discord: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<DiscordConfig, unknown, z.core.$ZodTypeInternals<DiscordConfig, unknown>>, z.ZodArray<z.ZodType<DiscordConfig, unknown, z.core.$ZodTypeInternals<DiscordConfig, unknown>>>]>>;
547
641
  telegram: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<TelegramConfig, unknown, z.core.$ZodTypeInternals<TelegramConfig, unknown>>, z.ZodArray<z.ZodType<TelegramConfig, unknown, z.core.$ZodTypeInternals<TelegramConfig, unknown>>>]>>;
548
642
  cloudwatch: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<CloudWatchConfig, unknown, z.core.$ZodTypeInternals<CloudWatchConfig, unknown>>, z.ZodArray<z.ZodType<CloudWatchConfig, unknown, z.core.$ZodTypeInternals<CloudWatchConfig, unknown>>>]>>;
643
+ zohoCliq: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
644
+ 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>>>;
645
+ rules: z.ZodOptional<z.ZodArray<z.ZodType<LevelRule, unknown, z.core.$ZodTypeInternals<LevelRule, unknown>>>>;
646
+ respectRuntimeOverrides: z.ZodOptional<z.ZodBoolean>;
647
+ batchSize: z.ZodOptional<z.ZodNumber>;
648
+ flushInterval: z.ZodOptional<z.ZodNumber>;
649
+ maxRetries: z.ZodOptional<z.ZodNumber>;
650
+ retryDelay: z.ZodOptional<z.ZodNumber>;
651
+ onError: z.ZodType<HttpTransportBaseConfig["onError"]>;
652
+ onDrop: z.ZodType<HttpTransportBaseConfig["onDrop"]>;
653
+ maxQueueSize: z.ZodOptional<z.ZodNumber>;
654
+ dropPolicy: z.ZodOptional<z.ZodEnum<{
655
+ "drop-oldest": "drop-oldest";
656
+ "drop-newest": "drop-newest";
657
+ }>>;
658
+ requestTimeout: z.ZodOptional<z.ZodNumber>;
659
+ webhookUrl: z.ZodOptional<z.ZodString>;
660
+ companyId: z.ZodOptional<z.ZodString>;
661
+ channel: z.ZodOptional<z.ZodString>;
662
+ region: z.ZodOptional<z.ZodString>;
663
+ apiKey: z.ZodString;
664
+ broadcast: z.ZodOptional<z.ZodBoolean>;
665
+ bot: z.ZodOptional<z.ZodObject<{
666
+ name: z.ZodString;
667
+ image: z.ZodOptional<z.ZodString>;
668
+ }, z.core.$strip>>;
669
+ includeTimestamp: z.ZodOptional<z.ZodBoolean>;
670
+ includeMeta: z.ZodOptional<z.ZodBoolean>;
671
+ }, z.core.$strip>, z.ZodArray<z.ZodObject<{
672
+ 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>>>;
673
+ rules: z.ZodOptional<z.ZodArray<z.ZodType<LevelRule, unknown, z.core.$ZodTypeInternals<LevelRule, unknown>>>>;
674
+ respectRuntimeOverrides: z.ZodOptional<z.ZodBoolean>;
675
+ batchSize: z.ZodOptional<z.ZodNumber>;
676
+ flushInterval: z.ZodOptional<z.ZodNumber>;
677
+ maxRetries: z.ZodOptional<z.ZodNumber>;
678
+ retryDelay: z.ZodOptional<z.ZodNumber>;
679
+ onError: z.ZodType<HttpTransportBaseConfig["onError"]>;
680
+ onDrop: z.ZodType<HttpTransportBaseConfig["onDrop"]>;
681
+ maxQueueSize: z.ZodOptional<z.ZodNumber>;
682
+ dropPolicy: z.ZodOptional<z.ZodEnum<{
683
+ "drop-oldest": "drop-oldest";
684
+ "drop-newest": "drop-newest";
685
+ }>>;
686
+ requestTimeout: z.ZodOptional<z.ZodNumber>;
687
+ webhookUrl: z.ZodOptional<z.ZodString>;
688
+ companyId: z.ZodOptional<z.ZodString>;
689
+ channel: z.ZodOptional<z.ZodString>;
690
+ region: z.ZodOptional<z.ZodString>;
691
+ apiKey: z.ZodString;
692
+ broadcast: z.ZodOptional<z.ZodBoolean>;
693
+ bot: z.ZodOptional<z.ZodObject<{
694
+ name: z.ZodString;
695
+ image: z.ZodOptional<z.ZodString>;
696
+ }, z.core.$strip>>;
697
+ includeTimestamp: z.ZodOptional<z.ZodBoolean>;
698
+ includeMeta: z.ZodOptional<z.ZodBoolean>;
699
+ }, z.core.$strip>>]>>;
549
700
  relay: z.ZodOptional<z.ZodType<RelayConfig, unknown, z.core.$ZodTypeInternals<RelayConfig, unknown>>>;
550
701
  caller: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodType<CallerConfig, unknown, z.core.$ZodTypeInternals<CallerConfig, unknown>>]>>;
551
702
  hostname: z.ZodOptional<z.ZodString>;
@@ -559,10 +710,61 @@ declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<{
559
710
  discord?: DiscordConfig | DiscordConfig[] | undefined;
560
711
  telegram?: TelegramConfig | TelegramConfig[] | undefined;
561
712
  cloudwatch?: CloudWatchConfig | CloudWatchConfig[] | undefined;
713
+ zohoCliq?: {
714
+ onError: ((error: Error, droppedMessages: unknown[]) => void) | undefined;
715
+ onDrop: ((droppedMessages: unknown[]) => void) | undefined;
716
+ apiKey: string;
717
+ level?: "off" | "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly" | undefined;
718
+ rules?: LevelRule[] | undefined;
719
+ respectRuntimeOverrides?: boolean | undefined;
720
+ batchSize?: number | undefined;
721
+ flushInterval?: number | undefined;
722
+ maxRetries?: number | undefined;
723
+ retryDelay?: number | undefined;
724
+ maxQueueSize?: number | undefined;
725
+ dropPolicy?: "drop-oldest" | "drop-newest" | undefined;
726
+ requestTimeout?: number | undefined;
727
+ webhookUrl?: string | undefined;
728
+ companyId?: string | undefined;
729
+ channel?: string | undefined;
730
+ region?: string | undefined;
731
+ broadcast?: boolean | undefined;
732
+ bot?: {
733
+ name: string;
734
+ image?: string | undefined;
735
+ } | undefined;
736
+ includeTimestamp?: boolean | undefined;
737
+ includeMeta?: boolean | undefined;
738
+ } | {
739
+ onError: ((error: Error, droppedMessages: unknown[]) => void) | undefined;
740
+ onDrop: ((droppedMessages: unknown[]) => void) | undefined;
741
+ apiKey: string;
742
+ level?: "off" | "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly" | undefined;
743
+ rules?: LevelRule[] | undefined;
744
+ respectRuntimeOverrides?: boolean | undefined;
745
+ batchSize?: number | undefined;
746
+ flushInterval?: number | undefined;
747
+ maxRetries?: number | undefined;
748
+ retryDelay?: number | undefined;
749
+ maxQueueSize?: number | undefined;
750
+ dropPolicy?: "drop-oldest" | "drop-newest" | undefined;
751
+ requestTimeout?: number | undefined;
752
+ webhookUrl?: string | undefined;
753
+ companyId?: string | undefined;
754
+ channel?: string | undefined;
755
+ region?: string | undefined;
756
+ broadcast?: boolean | undefined;
757
+ bot?: {
758
+ name: string;
759
+ image?: string | undefined;
760
+ } | undefined;
761
+ includeTimestamp?: boolean | undefined;
762
+ includeMeta?: boolean | undefined;
763
+ }[] | undefined;
562
764
  relay?: RelayConfig | undefined;
563
765
  caller?: boolean | CallerConfig | undefined;
564
766
  hostname?: string | undefined;
565
767
  autoShutdown?: boolean | AutoShutdownConfig | undefined;
566
768
  }>;
567
769
 
568
- 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 RequestIdOptions, type SerializedError, type SingletonLogger, type TelegramConfig, TelegramConfigSchema, TelegramTransport, type TimingResult, assertLogLevel, createMasker, createSingletonLogger, extractRequestId, flattenObject, formatCallerInfo, formatLogfmt, formatLogfmtValue, generateRequestId, getCallerInfo, getOrGenerateRequestId, isValidLogLevel, maskSecrets, matchesContext, measureAsync, measureSync, registerShutdown, safeValidateConfig, serializeError, validateConfig };
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 };