@rawnodes/logger 2.5.0 → 2.7.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 +62 -0
- package/dist/index.d.mts +98 -6
- package/dist/index.d.ts +98 -6
- package/dist/index.js +233 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +231 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -1
package/README.md
CHANGED
|
@@ -414,6 +414,68 @@ logger.for('payments').error('Payment failed');
|
|
|
414
414
|
logger.for('auth').error('Login failed');
|
|
415
415
|
```
|
|
416
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
|
+
|
|
417
479
|
## Singleton Pattern
|
|
418
480
|
|
|
419
481
|
For app-wide logging:
|
package/dist/index.d.mts
CHANGED
|
@@ -100,6 +100,12 @@ interface CallerInfo {
|
|
|
100
100
|
column?: number;
|
|
101
101
|
function?: string;
|
|
102
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
|
+
}
|
|
103
109
|
interface LoggerConfig {
|
|
104
110
|
level: LevelConfig;
|
|
105
111
|
console: ConsoleConfig;
|
|
@@ -111,6 +117,8 @@ interface LoggerConfig {
|
|
|
111
117
|
caller?: boolean | CallerConfig;
|
|
112
118
|
/** Hostname to include in all log entries. Defaults to os.hostname() if not specified */
|
|
113
119
|
hostname?: string;
|
|
120
|
+
/** Auto-register graceful shutdown handlers. Pass true for defaults or config object */
|
|
121
|
+
autoShutdown?: boolean | AutoShutdownConfig;
|
|
114
122
|
}
|
|
115
123
|
type LoggerContext = Record<string, unknown>;
|
|
116
124
|
type LevelOverrideMatch<TContext extends LoggerContext> = Partial<TContext> & {
|
|
@@ -141,6 +149,11 @@ declare class Logger<TContext extends LoggerContext = LoggerContext> {
|
|
|
141
149
|
removeLevelOverride(match: LevelOverrideMatch<TContext>): boolean;
|
|
142
150
|
clearLevelOverrides(): void;
|
|
143
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>;
|
|
144
157
|
profile(id: string, meta?: object): void;
|
|
145
158
|
error(errorOrMessage: Error | string, messageOrMeta?: string | Meta, meta?: Meta): void;
|
|
146
159
|
warn(message: string, meta?: Meta): void;
|
|
@@ -165,10 +178,6 @@ interface SingletonLogger<TContext extends LoggerContext> {
|
|
|
165
178
|
}
|
|
166
179
|
declare function createSingletonLogger<TContext extends LoggerContext = LoggerContext>(): SingletonLogger<TContext>;
|
|
167
180
|
|
|
168
|
-
declare function matchesContext(storeContext: LoggerContext | undefined, loggerContext: string | undefined, match: Record<string, unknown> & {
|
|
169
|
-
context?: string;
|
|
170
|
-
}): boolean;
|
|
171
|
-
|
|
172
181
|
interface BufferedMessage {
|
|
173
182
|
level: LogLevel;
|
|
174
183
|
message: string;
|
|
@@ -216,6 +225,10 @@ declare abstract class BaseHttpTransport extends EventEmitter {
|
|
|
216
225
|
protected abstract sendBatch(messages: BufferedMessage[]): Promise<void>;
|
|
217
226
|
}
|
|
218
227
|
|
|
228
|
+
declare function matchesContext(storeContext: LoggerContext | undefined, loggerContext: string | undefined, match: Record<string, unknown> & {
|
|
229
|
+
context?: string;
|
|
230
|
+
}): boolean;
|
|
231
|
+
|
|
219
232
|
declare class DiscordTransport extends BaseHttpTransport {
|
|
220
233
|
private config;
|
|
221
234
|
constructor(config: DiscordConfig);
|
|
@@ -295,7 +308,83 @@ declare function createMasker(options?: MaskSecretsOptions): (obj: unknown) => u
|
|
|
295
308
|
declare function getCallerInfo(config: CallerConfig, additionalOffset?: number): CallerInfo | undefined;
|
|
296
309
|
declare function formatCallerInfo(info: CallerInfo): string;
|
|
297
310
|
|
|
298
|
-
|
|
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
|
+
/**
|
|
340
|
+
* HTTP error data extracted from axios/fetch errors
|
|
341
|
+
*/
|
|
342
|
+
interface HttpErrorData {
|
|
343
|
+
/** HTTP status code (e.g., 400, 500) */
|
|
344
|
+
status?: number;
|
|
345
|
+
/** HTTP status text (e.g., "Bad Request") */
|
|
346
|
+
statusText?: string;
|
|
347
|
+
/** Response body data */
|
|
348
|
+
responseData?: unknown;
|
|
349
|
+
/** Request URL */
|
|
350
|
+
url?: string;
|
|
351
|
+
/** HTTP method (GET, POST, etc.) */
|
|
352
|
+
method?: string;
|
|
353
|
+
/** Error code (e.g., ECONNREFUSED, ETIMEDOUT) */
|
|
354
|
+
code?: string;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Serialized error data for logging
|
|
358
|
+
*/
|
|
359
|
+
interface SerializedError {
|
|
360
|
+
/** Error message */
|
|
361
|
+
errorMessage: string;
|
|
362
|
+
/** Stack trace */
|
|
363
|
+
stack?: string;
|
|
364
|
+
/** HTTP-specific data if present */
|
|
365
|
+
http?: HttpErrorData;
|
|
366
|
+
/** Error code for non-HTTP errors */
|
|
367
|
+
code?: string;
|
|
368
|
+
/** Error name/type */
|
|
369
|
+
errorName?: string;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Serializes an Error object for logging, extracting HTTP-specific data
|
|
373
|
+
* from axios/fetch errors while preserving standard error properties.
|
|
374
|
+
*
|
|
375
|
+
* @example
|
|
376
|
+
* // Axios error
|
|
377
|
+
* try {
|
|
378
|
+
* await axios.get('/api/data');
|
|
379
|
+
* } catch (error) {
|
|
380
|
+
* const serialized = serializeError(error);
|
|
381
|
+
* // serialized.http.status = 400
|
|
382
|
+
* // serialized.http.responseData = { error: "invalid input" }
|
|
383
|
+
* }
|
|
384
|
+
*/
|
|
385
|
+
declare function serializeError(error: unknown): SerializedError;
|
|
386
|
+
|
|
387
|
+
declare function flattenObject(obj: Record<string, unknown>, prefix?: string, ancestors?: WeakSet<object>, depth?: number): Record<string, unknown>;
|
|
299
388
|
declare function formatLogfmtValue(value: unknown): string;
|
|
300
389
|
declare function formatLogfmt(data: Record<string, unknown>): string;
|
|
301
390
|
|
|
@@ -315,6 +404,7 @@ declare const CloudWatchConfigSchema: z.ZodType<CloudWatchConfig>;
|
|
|
315
404
|
declare const LevelConfigObjectSchema: z.ZodType<LevelConfigObject>;
|
|
316
405
|
declare const LevelConfigSchema: z.ZodType<LevelConfig>;
|
|
317
406
|
declare const CallerConfigSchema: z.ZodType<CallerConfig>;
|
|
407
|
+
declare const AutoShutdownConfigSchema: z.ZodType<AutoShutdownConfig>;
|
|
318
408
|
declare const LoggerConfigSchema: z.ZodObject<{
|
|
319
409
|
level: z.ZodType<LevelConfig, unknown, z.core.$ZodTypeInternals<LevelConfig, unknown>>;
|
|
320
410
|
console: z.ZodType<ConsoleConfig, unknown, z.core.$ZodTypeInternals<ConsoleConfig, unknown>>;
|
|
@@ -324,6 +414,7 @@ declare const LoggerConfigSchema: z.ZodObject<{
|
|
|
324
414
|
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>>>]>>;
|
|
325
415
|
caller: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodType<CallerConfig, unknown, z.core.$ZodTypeInternals<CallerConfig, unknown>>]>>;
|
|
326
416
|
hostname: z.ZodOptional<z.ZodString>;
|
|
417
|
+
autoShutdown: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodType<AutoShutdownConfig, unknown, z.core.$ZodTypeInternals<AutoShutdownConfig, unknown>>]>>;
|
|
327
418
|
}, z.core.$strip>;
|
|
328
419
|
declare function validateConfig(config: unknown): z.infer<typeof LoggerConfigSchema>;
|
|
329
420
|
declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<{
|
|
@@ -335,6 +426,7 @@ declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<{
|
|
|
335
426
|
cloudwatch?: CloudWatchConfig | CloudWatchConfig[] | undefined;
|
|
336
427
|
caller?: boolean | CallerConfig | undefined;
|
|
337
428
|
hostname?: string | undefined;
|
|
429
|
+
autoShutdown?: boolean | AutoShutdownConfig | undefined;
|
|
338
430
|
}>;
|
|
339
431
|
|
|
340
|
-
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, 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, safeValidateConfig, validateConfig };
|
|
432
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -100,6 +100,12 @@ interface CallerInfo {
|
|
|
100
100
|
column?: number;
|
|
101
101
|
function?: string;
|
|
102
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
|
+
}
|
|
103
109
|
interface LoggerConfig {
|
|
104
110
|
level: LevelConfig;
|
|
105
111
|
console: ConsoleConfig;
|
|
@@ -111,6 +117,8 @@ interface LoggerConfig {
|
|
|
111
117
|
caller?: boolean | CallerConfig;
|
|
112
118
|
/** Hostname to include in all log entries. Defaults to os.hostname() if not specified */
|
|
113
119
|
hostname?: string;
|
|
120
|
+
/** Auto-register graceful shutdown handlers. Pass true for defaults or config object */
|
|
121
|
+
autoShutdown?: boolean | AutoShutdownConfig;
|
|
114
122
|
}
|
|
115
123
|
type LoggerContext = Record<string, unknown>;
|
|
116
124
|
type LevelOverrideMatch<TContext extends LoggerContext> = Partial<TContext> & {
|
|
@@ -141,6 +149,11 @@ declare class Logger<TContext extends LoggerContext = LoggerContext> {
|
|
|
141
149
|
removeLevelOverride(match: LevelOverrideMatch<TContext>): boolean;
|
|
142
150
|
clearLevelOverrides(): void;
|
|
143
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>;
|
|
144
157
|
profile(id: string, meta?: object): void;
|
|
145
158
|
error(errorOrMessage: Error | string, messageOrMeta?: string | Meta, meta?: Meta): void;
|
|
146
159
|
warn(message: string, meta?: Meta): void;
|
|
@@ -165,10 +178,6 @@ interface SingletonLogger<TContext extends LoggerContext> {
|
|
|
165
178
|
}
|
|
166
179
|
declare function createSingletonLogger<TContext extends LoggerContext = LoggerContext>(): SingletonLogger<TContext>;
|
|
167
180
|
|
|
168
|
-
declare function matchesContext(storeContext: LoggerContext | undefined, loggerContext: string | undefined, match: Record<string, unknown> & {
|
|
169
|
-
context?: string;
|
|
170
|
-
}): boolean;
|
|
171
|
-
|
|
172
181
|
interface BufferedMessage {
|
|
173
182
|
level: LogLevel;
|
|
174
183
|
message: string;
|
|
@@ -216,6 +225,10 @@ declare abstract class BaseHttpTransport extends EventEmitter {
|
|
|
216
225
|
protected abstract sendBatch(messages: BufferedMessage[]): Promise<void>;
|
|
217
226
|
}
|
|
218
227
|
|
|
228
|
+
declare function matchesContext(storeContext: LoggerContext | undefined, loggerContext: string | undefined, match: Record<string, unknown> & {
|
|
229
|
+
context?: string;
|
|
230
|
+
}): boolean;
|
|
231
|
+
|
|
219
232
|
declare class DiscordTransport extends BaseHttpTransport {
|
|
220
233
|
private config;
|
|
221
234
|
constructor(config: DiscordConfig);
|
|
@@ -295,7 +308,83 @@ declare function createMasker(options?: MaskSecretsOptions): (obj: unknown) => u
|
|
|
295
308
|
declare function getCallerInfo(config: CallerConfig, additionalOffset?: number): CallerInfo | undefined;
|
|
296
309
|
declare function formatCallerInfo(info: CallerInfo): string;
|
|
297
310
|
|
|
298
|
-
|
|
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
|
+
/**
|
|
340
|
+
* HTTP error data extracted from axios/fetch errors
|
|
341
|
+
*/
|
|
342
|
+
interface HttpErrorData {
|
|
343
|
+
/** HTTP status code (e.g., 400, 500) */
|
|
344
|
+
status?: number;
|
|
345
|
+
/** HTTP status text (e.g., "Bad Request") */
|
|
346
|
+
statusText?: string;
|
|
347
|
+
/** Response body data */
|
|
348
|
+
responseData?: unknown;
|
|
349
|
+
/** Request URL */
|
|
350
|
+
url?: string;
|
|
351
|
+
/** HTTP method (GET, POST, etc.) */
|
|
352
|
+
method?: string;
|
|
353
|
+
/** Error code (e.g., ECONNREFUSED, ETIMEDOUT) */
|
|
354
|
+
code?: string;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Serialized error data for logging
|
|
358
|
+
*/
|
|
359
|
+
interface SerializedError {
|
|
360
|
+
/** Error message */
|
|
361
|
+
errorMessage: string;
|
|
362
|
+
/** Stack trace */
|
|
363
|
+
stack?: string;
|
|
364
|
+
/** HTTP-specific data if present */
|
|
365
|
+
http?: HttpErrorData;
|
|
366
|
+
/** Error code for non-HTTP errors */
|
|
367
|
+
code?: string;
|
|
368
|
+
/** Error name/type */
|
|
369
|
+
errorName?: string;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Serializes an Error object for logging, extracting HTTP-specific data
|
|
373
|
+
* from axios/fetch errors while preserving standard error properties.
|
|
374
|
+
*
|
|
375
|
+
* @example
|
|
376
|
+
* // Axios error
|
|
377
|
+
* try {
|
|
378
|
+
* await axios.get('/api/data');
|
|
379
|
+
* } catch (error) {
|
|
380
|
+
* const serialized = serializeError(error);
|
|
381
|
+
* // serialized.http.status = 400
|
|
382
|
+
* // serialized.http.responseData = { error: "invalid input" }
|
|
383
|
+
* }
|
|
384
|
+
*/
|
|
385
|
+
declare function serializeError(error: unknown): SerializedError;
|
|
386
|
+
|
|
387
|
+
declare function flattenObject(obj: Record<string, unknown>, prefix?: string, ancestors?: WeakSet<object>, depth?: number): Record<string, unknown>;
|
|
299
388
|
declare function formatLogfmtValue(value: unknown): string;
|
|
300
389
|
declare function formatLogfmt(data: Record<string, unknown>): string;
|
|
301
390
|
|
|
@@ -315,6 +404,7 @@ declare const CloudWatchConfigSchema: z.ZodType<CloudWatchConfig>;
|
|
|
315
404
|
declare const LevelConfigObjectSchema: z.ZodType<LevelConfigObject>;
|
|
316
405
|
declare const LevelConfigSchema: z.ZodType<LevelConfig>;
|
|
317
406
|
declare const CallerConfigSchema: z.ZodType<CallerConfig>;
|
|
407
|
+
declare const AutoShutdownConfigSchema: z.ZodType<AutoShutdownConfig>;
|
|
318
408
|
declare const LoggerConfigSchema: z.ZodObject<{
|
|
319
409
|
level: z.ZodType<LevelConfig, unknown, z.core.$ZodTypeInternals<LevelConfig, unknown>>;
|
|
320
410
|
console: z.ZodType<ConsoleConfig, unknown, z.core.$ZodTypeInternals<ConsoleConfig, unknown>>;
|
|
@@ -324,6 +414,7 @@ declare const LoggerConfigSchema: z.ZodObject<{
|
|
|
324
414
|
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>>>]>>;
|
|
325
415
|
caller: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodType<CallerConfig, unknown, z.core.$ZodTypeInternals<CallerConfig, unknown>>]>>;
|
|
326
416
|
hostname: z.ZodOptional<z.ZodString>;
|
|
417
|
+
autoShutdown: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodType<AutoShutdownConfig, unknown, z.core.$ZodTypeInternals<AutoShutdownConfig, unknown>>]>>;
|
|
327
418
|
}, z.core.$strip>;
|
|
328
419
|
declare function validateConfig(config: unknown): z.infer<typeof LoggerConfigSchema>;
|
|
329
420
|
declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<{
|
|
@@ -335,6 +426,7 @@ declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<{
|
|
|
335
426
|
cloudwatch?: CloudWatchConfig | CloudWatchConfig[] | undefined;
|
|
336
427
|
caller?: boolean | CallerConfig | undefined;
|
|
337
428
|
hostname?: string | undefined;
|
|
429
|
+
autoShutdown?: boolean | AutoShutdownConfig | undefined;
|
|
338
430
|
}>;
|
|
339
431
|
|
|
340
|
-
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, 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, safeValidateConfig, validateConfig };
|
|
432
|
+
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 };
|