@rawnodes/logger 2.4.0 → 2.6.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
@@ -272,7 +272,6 @@ const logger = Logger.create({
272
272
  console: { format: 'plain' },
273
273
  cloudwatch: {
274
274
  logGroupName: '/app/my-service',
275
- logStreamName: `${hostname}-${Date.now()}`,
276
275
  region: 'us-east-1',
277
276
  accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
278
277
  secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
@@ -284,6 +283,91 @@ const logger = Logger.create({
284
283
  });
285
284
  ```
286
285
 
286
+ #### Log Stream Name
287
+
288
+ The `logStreamName` field is optional and supports multiple configuration formats:
289
+
290
+ ```typescript
291
+ // Option 1: Static string
292
+ cloudwatch: {
293
+ logGroupName: '/app/my-service',
294
+ logStreamName: 'my-static-stream',
295
+ // ...
296
+ }
297
+
298
+ // Option 2: Predefined pattern
299
+ cloudwatch: {
300
+ logGroupName: '/app/my-service',
301
+ logStreamName: { pattern: 'hostname-date' },
302
+ // ...
303
+ }
304
+
305
+ // Option 3: Custom template
306
+ cloudwatch: {
307
+ logGroupName: '/app/my-service',
308
+ logStreamName: { template: '{hostname}/{env}/{date}' },
309
+ // ...
310
+ }
311
+
312
+ // Option 4: Omit for default (hostname)
313
+ cloudwatch: {
314
+ logGroupName: '/app/my-service',
315
+ // logStreamName defaults to hostname
316
+ // ...
317
+ }
318
+ ```
319
+
320
+ **Available patterns:**
321
+
322
+ | Pattern | Example Output |
323
+ |---------|----------------|
324
+ | `hostname` | `my-server` |
325
+ | `hostname-date` | `my-server/2025-01-15` |
326
+ | `hostname-uuid` | `my-server-a1b2c3d4` |
327
+ | `date` | `2025-01-15` |
328
+ | `uuid` | `a1b2c3d4-e5f6-7890-abcd` |
329
+
330
+ **Template variables:**
331
+
332
+ | Variable | Description |
333
+ |----------|-------------|
334
+ | `{hostname}` | Server hostname (config.hostname → HOSTNAME env → os.hostname()) |
335
+ | `{date}` | Current date (YYYY-MM-DD) |
336
+ | `{datetime}` | Current datetime (YYYY-MM-DD-HH-mm-ss) |
337
+ | `{uuid}` | 8-char UUID (generated once at startup) |
338
+ | `{pid}` | Process ID |
339
+ | `{env}` | NODE_ENV (default: "development") |
340
+
341
+ **Hostname resolution priority:**
342
+ 1. `config.hostname` (from logger config)
343
+ 2. `process.env.HOSTNAME` (useful in Docker/Kubernetes)
344
+ 3. `os.hostname()`
345
+
346
+ **Examples:**
347
+
348
+ ```typescript
349
+ // Kubernetes-friendly: pod name as stream
350
+ cloudwatch: {
351
+ logGroupName: '/app/my-service/production',
352
+ logStreamName: { pattern: 'hostname' }, // -> "my-app-pod-abc123"
353
+ // ...
354
+ }
355
+
356
+ // Daily rotation with hostname
357
+ cloudwatch: {
358
+ logGroupName: '/app/my-service',
359
+ logStreamName: { pattern: 'hostname-date' }, // -> "my-server/2025-01-15"
360
+ // ...
361
+ }
362
+
363
+ // Custom format with environment
364
+ cloudwatch: {
365
+ logGroupName: '/app/my-service',
366
+ logStreamName: { template: '{env}/{hostname}/{date}' }, // -> "production/my-server/2025-01-15"
367
+ // ...
368
+ }
369
+ ```
370
+
287
371
  ### Transport Options
288
372
 
289
373
  All external transports support:
@@ -330,6 +414,68 @@ logger.for('payments').error('Payment failed');
330
414
  logger.for('auth').error('Login failed');
331
415
  ```
332
416
 
417
+ ## Graceful Shutdown
418
+
419
+ External transports (Discord, Telegram, CloudWatch) buffer messages before sending. To ensure no logs are lost on process exit, use graceful shutdown.
420
+
421
+ ### Automatic (Recommended)
422
+
423
+ Enable `autoShutdown` in config to automatically handle SIGTERM/SIGINT:
424
+
425
+ ```typescript
426
+ const logger = Logger.create({
427
+ level: 'info',
428
+ console: { format: 'plain' },
429
+ cloudwatch: { /* ... */ },
430
+ autoShutdown: true, // Auto-register shutdown handlers
431
+ });
432
+
433
+ // Or with options:
434
+ const logger = Logger.create({
435
+ level: 'info',
436
+ console: { format: 'plain' },
437
+ cloudwatch: { /* ... */ },
438
+ autoShutdown: {
439
+ timeout: 10000, // Max wait time (default: 5000ms)
440
+ signals: ['SIGTERM'], // Signals to handle (default: ['SIGTERM', 'SIGINT'])
441
+ },
442
+ });
443
+ ```
444
+
445
+ ### Manual
446
+
447
+ For more control, use `registerShutdown` or call `shutdown()` directly:
448
+
449
+ ```typescript
450
+ import { Logger, registerShutdown } from '@rawnodes/logger';
451
+
452
+ const logger = Logger.create(config);
453
+
454
+ // Option 1: Register handlers manually
455
+ registerShutdown(logger, {
456
+ timeout: 10000,
457
+ onShutdown: async () => {
458
+ console.log('Flushing logs...');
459
+ },
460
+ });
461
+
462
+ // Option 2: Call shutdown directly (e.g., in your own signal handler)
463
+ process.on('SIGTERM', async () => {
464
+ await logger.shutdown(); // Flush all buffered messages
465
+ process.exit(0);
466
+ });
467
+ ```
468
+
469
+ ### In Tests
470
+
471
+ For tests, call `shutdown()` in `afterAll` to flush pending logs:
472
+
473
+ ```typescript
474
+ afterAll(async () => {
475
+ await logger.shutdown();
476
+ });
477
+ ```
478
+
333
479
  ## Singleton Pattern
334
480
 
335
481
  For app-wide logging:
package/dist/index.d.mts CHANGED
@@ -64,9 +64,19 @@ interface TelegramConfig extends HttpTransportBaseConfig {
64
64
  threadId?: number;
65
65
  replyToMessageId?: number;
66
66
  }
67
+ type LogStreamPattern = 'hostname' | 'hostname-date' | 'hostname-uuid' | 'date' | 'uuid';
68
+ interface LogStreamPatternConfig {
69
+ pattern: LogStreamPattern;
70
+ }
71
+ interface LogStreamTemplateConfig {
72
+ /** Custom template with variables: {hostname}, {date}, {datetime}, {uuid}, {pid}, {env} */
73
+ template: string;
74
+ }
75
+ type LogStreamName = string | LogStreamPatternConfig | LogStreamTemplateConfig;
67
76
  interface CloudWatchConfig extends HttpTransportBaseConfig {
68
77
  logGroupName: string;
69
- logStreamName: string;
78
+ /** Log stream name - string, pattern config, or template config. Defaults to hostname pattern */
79
+ logStreamName?: LogStreamName;
70
80
  region: string;
71
81
  accessKeyId: string;
72
82
  secretAccessKey: string;
@@ -90,6 +100,12 @@ interface CallerInfo {
90
100
  column?: number;
91
101
  function?: string;
92
102
  }
103
+ interface AutoShutdownConfig {
104
+ /** Timeout in ms before forcing exit (default: 5000) */
105
+ timeout?: number;
106
+ /** Custom signals to handle (default: ['SIGTERM', 'SIGINT']) */
107
+ signals?: NodeJS.Signals[];
108
+ }
93
109
  interface LoggerConfig {
94
110
  level: LevelConfig;
95
111
  console: ConsoleConfig;
@@ -101,6 +117,8 @@ interface LoggerConfig {
101
117
  caller?: boolean | CallerConfig;
102
118
  /** Hostname to include in all log entries. Defaults to os.hostname() if not specified */
103
119
  hostname?: string;
120
+ /** Auto-register graceful shutdown handlers. Pass true for defaults or config object */
121
+ autoShutdown?: boolean | AutoShutdownConfig;
104
122
  }
105
123
  type LoggerContext = Record<string, unknown>;
106
124
  type LevelOverrideMatch<TContext extends LoggerContext> = Partial<TContext> & {
@@ -131,6 +149,11 @@ declare class Logger<TContext extends LoggerContext = LoggerContext> {
131
149
  removeLevelOverride(match: LevelOverrideMatch<TContext>): boolean;
132
150
  clearLevelOverrides(): void;
133
151
  getLevelOverrides(): LevelOverride<TContext>[];
152
+ /**
153
+ * Gracefully shutdown the logger, flushing all pending messages.
154
+ * Should be called before process exit to ensure no logs are lost.
155
+ */
156
+ shutdown(): Promise<void>;
134
157
  profile(id: string, meta?: object): void;
135
158
  error(errorOrMessage: Error | string, messageOrMeta?: string | Meta, meta?: Meta): void;
136
159
  warn(message: string, meta?: Meta): void;
@@ -155,10 +178,6 @@ interface SingletonLogger<TContext extends LoggerContext> {
155
178
  }
156
179
  declare function createSingletonLogger<TContext extends LoggerContext = LoggerContext>(): SingletonLogger<TContext>;
157
180
 
158
- declare function matchesContext(storeContext: LoggerContext | undefined, loggerContext: string | undefined, match: Record<string, unknown> & {
159
- context?: string;
160
- }): boolean;
161
-
162
181
  interface BufferedMessage {
163
182
  level: LogLevel;
164
183
  message: string;
@@ -206,6 +225,10 @@ declare abstract class BaseHttpTransport extends EventEmitter {
206
225
  protected abstract sendBatch(messages: BufferedMessage[]): Promise<void>;
207
226
  }
208
227
 
228
+ declare function matchesContext(storeContext: LoggerContext | undefined, loggerContext: string | undefined, match: Record<string, unknown> & {
229
+ context?: string;
230
+ }): boolean;
231
+
209
232
  declare class DiscordTransport extends BaseHttpTransport {
210
233
  private config;
211
234
  constructor(config: DiscordConfig);
@@ -240,7 +263,8 @@ declare class CloudWatchTransport extends BaseHttpTransport {
240
263
  private sequenceToken;
241
264
  private initialized;
242
265
  private initPromise;
243
- constructor(config: CloudWatchConfig);
266
+ private resolvedLogStreamName;
267
+ constructor(config: CloudWatchConfig, configHostname?: string);
244
268
  protected sendBatch(messages: BufferedMessage[]): Promise<void>;
245
269
  private ensureInitialized;
246
270
  private initialize;
@@ -284,7 +308,35 @@ declare function createMasker(options?: MaskSecretsOptions): (obj: unknown) => u
284
308
  declare function getCallerInfo(config: CallerConfig, additionalOffset?: number): CallerInfo | undefined;
285
309
  declare function formatCallerInfo(info: CallerInfo): string;
286
310
 
287
- declare function flattenObject(obj: Record<string, unknown>, prefix?: string): Record<string, unknown>;
311
+ interface GracefulShutdownOptions {
312
+ /** Timeout in ms before forcing exit (default: 5000) */
313
+ timeout?: number;
314
+ /** Exit code on successful shutdown (default: 0) */
315
+ exitCode?: number;
316
+ /** Custom signals to handle (default: ['SIGTERM', 'SIGINT']) */
317
+ signals?: NodeJS.Signals[];
318
+ /** Called before shutdown starts */
319
+ onShutdown?: () => void | Promise<void>;
320
+ }
321
+ /**
322
+ * Register graceful shutdown handlers for the logger.
323
+ * Ensures all buffered logs are flushed before process exit.
324
+ *
325
+ * @example
326
+ * ```typescript
327
+ * const logger = Logger.create(config);
328
+ * registerShutdown(logger);
329
+ *
330
+ * // Or with options:
331
+ * registerShutdown(logger, {
332
+ * timeout: 10000,
333
+ * onShutdown: () => console.log('Shutting down...'),
334
+ * });
335
+ * ```
336
+ */
337
+ declare function registerShutdown<TContext extends LoggerContext>(logger: Logger<TContext>, options?: GracefulShutdownOptions): () => Promise<void>;
338
+
339
+ declare function flattenObject(obj: Record<string, unknown>, prefix?: string, ancestors?: WeakSet<object>, depth?: number): Record<string, unknown>;
288
340
  declare function formatLogfmtValue(value: unknown): string;
289
341
  declare function formatLogfmt(data: Record<string, unknown>): string;
290
342
 
@@ -296,10 +348,15 @@ declare const FileConfigSchema: z.ZodType<FileConfig>;
296
348
  declare const HttpTransportBaseConfigSchema: z.ZodType<HttpTransportBaseConfig>;
297
349
  declare const DiscordConfigSchema: z.ZodType<DiscordConfig>;
298
350
  declare const TelegramConfigSchema: z.ZodType<TelegramConfig>;
351
+ declare const LogStreamPatternSchema: z.ZodType<LogStreamPattern>;
352
+ declare const LogStreamPatternConfigSchema: z.ZodType<LogStreamPatternConfig>;
353
+ declare const LogStreamTemplateConfigSchema: z.ZodType<LogStreamTemplateConfig>;
354
+ declare const LogStreamNameSchema: z.ZodType<LogStreamName>;
299
355
  declare const CloudWatchConfigSchema: z.ZodType<CloudWatchConfig>;
300
356
  declare const LevelConfigObjectSchema: z.ZodType<LevelConfigObject>;
301
357
  declare const LevelConfigSchema: z.ZodType<LevelConfig>;
302
358
  declare const CallerConfigSchema: z.ZodType<CallerConfig>;
359
+ declare const AutoShutdownConfigSchema: z.ZodType<AutoShutdownConfig>;
303
360
  declare const LoggerConfigSchema: z.ZodObject<{
304
361
  level: z.ZodType<LevelConfig, unknown, z.core.$ZodTypeInternals<LevelConfig, unknown>>;
305
362
  console: z.ZodType<ConsoleConfig, unknown, z.core.$ZodTypeInternals<ConsoleConfig, unknown>>;
@@ -309,6 +366,7 @@ declare const LoggerConfigSchema: z.ZodObject<{
309
366
  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>>>]>>;
310
367
  caller: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodType<CallerConfig, unknown, z.core.$ZodTypeInternals<CallerConfig, unknown>>]>>;
311
368
  hostname: z.ZodOptional<z.ZodString>;
369
+ autoShutdown: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodType<AutoShutdownConfig, unknown, z.core.$ZodTypeInternals<AutoShutdownConfig, unknown>>]>>;
312
370
  }, z.core.$strip>;
313
371
  declare function validateConfig(config: unknown): z.infer<typeof LoggerConfigSchema>;
314
372
  declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<{
@@ -320,6 +378,7 @@ declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<{
320
378
  cloudwatch?: CloudWatchConfig | CloudWatchConfig[] | undefined;
321
379
  caller?: boolean | CallerConfig | undefined;
322
380
  hostname?: string | undefined;
381
+ autoShutdown?: boolean | AutoShutdownConfig | undefined;
323
382
  }>;
324
383
 
325
- export { 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 HttpTransportBaseConfig, HttpTransportBaseConfigSchema, LOG_LEVELS, type LevelConfig, type LevelConfigObject, LevelConfigObjectSchema, LevelConfigSchema, type LevelOverride, type LevelOverrideMatch, type LevelRule, LevelRuleSchema, type LogFormat, LogFormatSchema, type LogLevel, LogLevelSchema, Logger, type LoggerConfig, LoggerConfigSchema, type LoggerContext, LoggerStore, type MaskSecretsOptions, MessageBuffer, type Meta, type RequestIdOptions, type SingletonLogger, type TelegramConfig, TelegramConfigSchema, TelegramTransport, type TimingResult, assertLogLevel, createMasker, createSingletonLogger, extractRequestId, flattenObject, formatCallerInfo, formatLogfmt, formatLogfmtValue, generateRequestId, getCallerInfo, getOrGenerateRequestId, isValidLogLevel, maskSecrets, matchesContext, measureAsync, measureSync, safeValidateConfig, validateConfig };
384
+ 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 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 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, validateConfig };
package/dist/index.d.ts CHANGED
@@ -64,9 +64,19 @@ interface TelegramConfig extends HttpTransportBaseConfig {
64
64
  threadId?: number;
65
65
  replyToMessageId?: number;
66
66
  }
67
+ type LogStreamPattern = 'hostname' | 'hostname-date' | 'hostname-uuid' | 'date' | 'uuid';
68
+ interface LogStreamPatternConfig {
69
+ pattern: LogStreamPattern;
70
+ }
71
+ interface LogStreamTemplateConfig {
72
+ /** Custom template with variables: {hostname}, {date}, {datetime}, {uuid}, {pid}, {env} */
73
+ template: string;
74
+ }
75
+ type LogStreamName = string | LogStreamPatternConfig | LogStreamTemplateConfig;
67
76
  interface CloudWatchConfig extends HttpTransportBaseConfig {
68
77
  logGroupName: string;
69
- logStreamName: string;
78
+ /** Log stream name - string, pattern config, or template config. Defaults to hostname pattern */
79
+ logStreamName?: LogStreamName;
70
80
  region: string;
71
81
  accessKeyId: string;
72
82
  secretAccessKey: string;
@@ -90,6 +100,12 @@ interface CallerInfo {
90
100
  column?: number;
91
101
  function?: string;
92
102
  }
103
+ interface AutoShutdownConfig {
104
+ /** Timeout in ms before forcing exit (default: 5000) */
105
+ timeout?: number;
106
+ /** Custom signals to handle (default: ['SIGTERM', 'SIGINT']) */
107
+ signals?: NodeJS.Signals[];
108
+ }
93
109
  interface LoggerConfig {
94
110
  level: LevelConfig;
95
111
  console: ConsoleConfig;
@@ -101,6 +117,8 @@ interface LoggerConfig {
101
117
  caller?: boolean | CallerConfig;
102
118
  /** Hostname to include in all log entries. Defaults to os.hostname() if not specified */
103
119
  hostname?: string;
120
+ /** Auto-register graceful shutdown handlers. Pass true for defaults or config object */
121
+ autoShutdown?: boolean | AutoShutdownConfig;
104
122
  }
105
123
  type LoggerContext = Record<string, unknown>;
106
124
  type LevelOverrideMatch<TContext extends LoggerContext> = Partial<TContext> & {
@@ -131,6 +149,11 @@ declare class Logger<TContext extends LoggerContext = LoggerContext> {
131
149
  removeLevelOverride(match: LevelOverrideMatch<TContext>): boolean;
132
150
  clearLevelOverrides(): void;
133
151
  getLevelOverrides(): LevelOverride<TContext>[];
152
+ /**
153
+ * Gracefully shutdown the logger, flushing all pending messages.
154
+ * Should be called before process exit to ensure no logs are lost.
155
+ */
156
+ shutdown(): Promise<void>;
134
157
  profile(id: string, meta?: object): void;
135
158
  error(errorOrMessage: Error | string, messageOrMeta?: string | Meta, meta?: Meta): void;
136
159
  warn(message: string, meta?: Meta): void;
@@ -155,10 +178,6 @@ interface SingletonLogger<TContext extends LoggerContext> {
155
178
  }
156
179
  declare function createSingletonLogger<TContext extends LoggerContext = LoggerContext>(): SingletonLogger<TContext>;
157
180
 
158
- declare function matchesContext(storeContext: LoggerContext | undefined, loggerContext: string | undefined, match: Record<string, unknown> & {
159
- context?: string;
160
- }): boolean;
161
-
162
181
  interface BufferedMessage {
163
182
  level: LogLevel;
164
183
  message: string;
@@ -206,6 +225,10 @@ declare abstract class BaseHttpTransport extends EventEmitter {
206
225
  protected abstract sendBatch(messages: BufferedMessage[]): Promise<void>;
207
226
  }
208
227
 
228
+ declare function matchesContext(storeContext: LoggerContext | undefined, loggerContext: string | undefined, match: Record<string, unknown> & {
229
+ context?: string;
230
+ }): boolean;
231
+
209
232
  declare class DiscordTransport extends BaseHttpTransport {
210
233
  private config;
211
234
  constructor(config: DiscordConfig);
@@ -240,7 +263,8 @@ declare class CloudWatchTransport extends BaseHttpTransport {
240
263
  private sequenceToken;
241
264
  private initialized;
242
265
  private initPromise;
243
- constructor(config: CloudWatchConfig);
266
+ private resolvedLogStreamName;
267
+ constructor(config: CloudWatchConfig, configHostname?: string);
244
268
  protected sendBatch(messages: BufferedMessage[]): Promise<void>;
245
269
  private ensureInitialized;
246
270
  private initialize;
@@ -284,7 +308,35 @@ declare function createMasker(options?: MaskSecretsOptions): (obj: unknown) => u
284
308
  declare function getCallerInfo(config: CallerConfig, additionalOffset?: number): CallerInfo | undefined;
285
309
  declare function formatCallerInfo(info: CallerInfo): string;
286
310
 
287
- declare function flattenObject(obj: Record<string, unknown>, prefix?: string): Record<string, unknown>;
311
+ interface GracefulShutdownOptions {
312
+ /** Timeout in ms before forcing exit (default: 5000) */
313
+ timeout?: number;
314
+ /** Exit code on successful shutdown (default: 0) */
315
+ exitCode?: number;
316
+ /** Custom signals to handle (default: ['SIGTERM', 'SIGINT']) */
317
+ signals?: NodeJS.Signals[];
318
+ /** Called before shutdown starts */
319
+ onShutdown?: () => void | Promise<void>;
320
+ }
321
+ /**
322
+ * Register graceful shutdown handlers for the logger.
323
+ * Ensures all buffered logs are flushed before process exit.
324
+ *
325
+ * @example
326
+ * ```typescript
327
+ * const logger = Logger.create(config);
328
+ * registerShutdown(logger);
329
+ *
330
+ * // Or with options:
331
+ * registerShutdown(logger, {
332
+ * timeout: 10000,
333
+ * onShutdown: () => console.log('Shutting down...'),
334
+ * });
335
+ * ```
336
+ */
337
+ declare function registerShutdown<TContext extends LoggerContext>(logger: Logger<TContext>, options?: GracefulShutdownOptions): () => Promise<void>;
338
+
339
+ declare function flattenObject(obj: Record<string, unknown>, prefix?: string, ancestors?: WeakSet<object>, depth?: number): Record<string, unknown>;
288
340
  declare function formatLogfmtValue(value: unknown): string;
289
341
  declare function formatLogfmt(data: Record<string, unknown>): string;
290
342
 
@@ -296,10 +348,15 @@ declare const FileConfigSchema: z.ZodType<FileConfig>;
296
348
  declare const HttpTransportBaseConfigSchema: z.ZodType<HttpTransportBaseConfig>;
297
349
  declare const DiscordConfigSchema: z.ZodType<DiscordConfig>;
298
350
  declare const TelegramConfigSchema: z.ZodType<TelegramConfig>;
351
+ declare const LogStreamPatternSchema: z.ZodType<LogStreamPattern>;
352
+ declare const LogStreamPatternConfigSchema: z.ZodType<LogStreamPatternConfig>;
353
+ declare const LogStreamTemplateConfigSchema: z.ZodType<LogStreamTemplateConfig>;
354
+ declare const LogStreamNameSchema: z.ZodType<LogStreamName>;
299
355
  declare const CloudWatchConfigSchema: z.ZodType<CloudWatchConfig>;
300
356
  declare const LevelConfigObjectSchema: z.ZodType<LevelConfigObject>;
301
357
  declare const LevelConfigSchema: z.ZodType<LevelConfig>;
302
358
  declare const CallerConfigSchema: z.ZodType<CallerConfig>;
359
+ declare const AutoShutdownConfigSchema: z.ZodType<AutoShutdownConfig>;
303
360
  declare const LoggerConfigSchema: z.ZodObject<{
304
361
  level: z.ZodType<LevelConfig, unknown, z.core.$ZodTypeInternals<LevelConfig, unknown>>;
305
362
  console: z.ZodType<ConsoleConfig, unknown, z.core.$ZodTypeInternals<ConsoleConfig, unknown>>;
@@ -309,6 +366,7 @@ declare const LoggerConfigSchema: z.ZodObject<{
309
366
  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>>>]>>;
310
367
  caller: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodType<CallerConfig, unknown, z.core.$ZodTypeInternals<CallerConfig, unknown>>]>>;
311
368
  hostname: z.ZodOptional<z.ZodString>;
369
+ autoShutdown: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodType<AutoShutdownConfig, unknown, z.core.$ZodTypeInternals<AutoShutdownConfig, unknown>>]>>;
312
370
  }, z.core.$strip>;
313
371
  declare function validateConfig(config: unknown): z.infer<typeof LoggerConfigSchema>;
314
372
  declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<{
@@ -320,6 +378,7 @@ declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<{
320
378
  cloudwatch?: CloudWatchConfig | CloudWatchConfig[] | undefined;
321
379
  caller?: boolean | CallerConfig | undefined;
322
380
  hostname?: string | undefined;
381
+ autoShutdown?: boolean | AutoShutdownConfig | undefined;
323
382
  }>;
324
383
 
325
- export { 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 HttpTransportBaseConfig, HttpTransportBaseConfigSchema, LOG_LEVELS, type LevelConfig, type LevelConfigObject, LevelConfigObjectSchema, LevelConfigSchema, type LevelOverride, type LevelOverrideMatch, type LevelRule, LevelRuleSchema, type LogFormat, LogFormatSchema, type LogLevel, LogLevelSchema, Logger, type LoggerConfig, LoggerConfigSchema, type LoggerContext, LoggerStore, type MaskSecretsOptions, MessageBuffer, type Meta, type RequestIdOptions, type SingletonLogger, type TelegramConfig, TelegramConfigSchema, TelegramTransport, type TimingResult, assertLogLevel, createMasker, createSingletonLogger, extractRequestId, flattenObject, formatCallerInfo, formatLogfmt, formatLogfmtValue, generateRequestId, getCallerInfo, getOrGenerateRequestId, isValidLogLevel, maskSecrets, matchesContext, measureAsync, measureSync, safeValidateConfig, validateConfig };
384
+ 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 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 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, validateConfig };