@mrxsys/mrx-core 2.11.0-1-and-269-20251003 → 2.11.1-1-and-275-20251023

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.
Files changed (46) hide show
  1. package/dist/{chunk-dzfefxjq.js → chunk-pjv1ekwr.js} +32 -0
  2. package/dist/chunk-rz5p4j3p.js +13 -0
  3. package/dist/modules/elysia/cache/cache.d.ts +7 -13
  4. package/dist/modules/elysia/cache/index.js +66 -46
  5. package/dist/modules/elysia/cache/types/cache-item.d.ts +0 -1
  6. package/dist/modules/elysia/cache/types/cache-options.d.ts +2 -11
  7. package/dist/modules/elysia/crud/index.js +10 -10
  8. package/dist/modules/elysia/crud/operations/index.js +1 -1
  9. package/dist/modules/elysia/rate-limit/index.js +51 -26
  10. package/dist/modules/elysia/rate-limit/rate-limit.d.ts +361 -32
  11. package/dist/modules/elysia/rate-limit/types/rate-limit-options.d.ts +0 -9
  12. package/dist/modules/kv-store/bun-redis/bun-redis-store.d.ts +25 -0
  13. package/dist/modules/kv-store/bun-redis/index.d.ts +1 -0
  14. package/dist/modules/kv-store/bun-redis/index.js +76 -0
  15. package/dist/modules/kv-store/ioredis/index.js +4 -10
  16. package/dist/modules/kv-store/ioredis/ioredis-store.d.ts +0 -82
  17. package/dist/modules/kv-store/memory/index.js +98 -4
  18. package/dist/modules/kv-store/memory/memory-store.d.ts +0 -84
  19. package/dist/modules/kv-store/types/kv-store.d.ts +2 -2
  20. package/dist/modules/logger/enums/index.js +1 -1
  21. package/dist/modules/logger/enums/logger-error-keys.d.ts +6 -3
  22. package/dist/modules/logger/events/logger-events.d.ts +12 -3
  23. package/dist/modules/logger/index.js +173 -81
  24. package/dist/modules/logger/logger.d.ts +115 -133
  25. package/dist/modules/logger/sinks/console-logger.d.ts +2 -16
  26. package/dist/modules/logger/sinks/devnull-logger.d.ts +8 -0
  27. package/dist/modules/logger/sinks/file-logger/enums/file-logger-error-keys.d.ts +3 -0
  28. package/dist/modules/logger/sinks/file-logger/file-logger.d.ts +25 -0
  29. package/dist/modules/logger/sinks/index.d.ts +4 -2
  30. package/dist/modules/logger/sinks/index.js +54 -31
  31. package/dist/modules/logger/types/index.d.ts +6 -6
  32. package/dist/modules/logger/types/log-levels.d.ts +1 -4
  33. package/dist/modules/logger/types/logger-options.d.ts +41 -0
  34. package/dist/modules/logger/types/logger-sink.d.ts +12 -3
  35. package/dist/modules/logger/types/sink-bodies-intersection.d.ts +2 -0
  36. package/dist/modules/logger/types/sink-body.d.ts +1 -1
  37. package/dist/modules/logger/types/sink-map.d.ts +1 -1
  38. package/package.json +26 -21
  39. package/dist/chunk-b23dvm2d.js +0 -29
  40. package/dist/chunk-b96fm9ph.js +0 -10
  41. package/dist/chunk-e30paw8a.js +0 -101
  42. package/dist/modules/elysia/cache/utils/index.d.ts +0 -1
  43. package/dist/modules/elysia/cache/utils/index.js +0 -7
  44. package/dist/modules/logger/sinks/file-logger.d.ts +0 -25
  45. package/dist/modules/logger/types/bodies-intersection.d.ts +0 -2
  46. package/dist/modules/logger/types/log-stream-chunk.d.ts +0 -15
@@ -1,189 +1,171 @@
1
1
  import { TypedEventEmitter } from '../../modules/typed-event-emitter/typed-event-emitter';
2
2
  import type { LoggerEvent } from './events/logger-events';
3
- import type { BodiesIntersection } from './types/bodies-intersection';
3
+ import type { LoggerOptions } from './types/logger-options';
4
4
  import type { LoggerSink } from './types/logger-sink';
5
+ import type { SinkBodiesIntersection } from './types/sink-bodies-intersection';
5
6
  import type { SinkMap } from './types/sink-map';
6
- /**
7
- * Logger provides a flexible, type-safe logging system that allows multiple sinks for log output.
8
- * The logger uses a transform stream to process log entries and execute the logging sinks.
9
- *
10
- * Logger extends the TypedEventEmitter class to emit typed events when an error occurs or when the logger ends.
11
- * The logger can log messages with different levels: error, warn, info, debug, and log.
12
- *
13
- * @template TSinks - The map of sink names to LoggerStrategy types.
14
- */
15
7
  export declare class Logger<TSinks extends SinkMap = {}> extends TypedEventEmitter<LoggerEvent> {
16
8
  /**
17
- * The map of sinks.
9
+ * Map of registered sinks (logging destinations)
18
10
  */
19
11
  private readonly _sinks;
20
12
  /**
21
- * The transform stream for processing log entries.
13
+ * List of registered sink keys for quick access
22
14
  */
23
- private readonly _logStream;
15
+ private readonly _sinkKeys;
24
16
  /**
25
- * The queue of pending log entries.
17
+ * Worker instance handling log processing
26
18
  */
27
- private readonly _pendingLogs;
19
+ private readonly _worker;
28
20
  /**
29
- * The maximum number of pending logs.
30
- * @defaultValue 10_000
21
+ * Maximum number of pending log messages allowed in the queue
31
22
  */
32
23
  private readonly _maxPendingLogs;
33
24
  /**
34
- * Flag to indicate if the logger is currently writing logs.
25
+ * Maximum number of messages in flight to the worker
26
+ */
27
+ private readonly _maxMessagesInFlight;
28
+ /**
29
+ * Number of logs to batch before sending to worker
30
+ */
31
+ private readonly _batchSize;
32
+ /**
33
+ * Timeout in milliseconds before flushing incomplete batch
34
+ */
35
+ private readonly _batchTimeout;
36
+ /**
37
+ * Whether to auto flush and close on process exit
38
+ */
39
+ private readonly _autoEnd;
40
+ /**
41
+ * Whether to flush before process exit
42
+ */
43
+ private readonly _flushOnBeforeExit;
44
+ /**
45
+ * Queue of pending log messages
46
+ */
47
+ private readonly _pendingLogs;
48
+ /**
49
+ * Number of log messages currently being processed by the worker
50
+ */
51
+ private _messagesInFlight;
52
+ /**
53
+ * Timer for batching log messages
54
+ */
55
+ private _batchTimer;
56
+ /**
57
+ * Whether the logger is currently writing log messages to the worker
35
58
  */
36
59
  private _isWriting;
37
60
  /**
38
- * Construct a Logger.
39
- *
40
- * @template TStrategies - The map of sink names to LoggerStrategy types.
41
- *
42
- * @param sinks - Initial sinks map.
43
- *
44
- * @param maxPendingLogs - Maximum number of logs in the queue (default: 10_000)
61
+ * Resolvers for flush promises
45
62
  */
46
- constructor(sinks?: TSinks, maxPendingLogs?: number);
63
+ private readonly _flushResolvers;
47
64
  /**
48
- * Register a new logging sink.
49
- *
50
- * @template Key - The name of the sink.
51
- * @template Sink - The sink type.
52
- *
53
- * @param name - The name of the sink.
54
- * @param sink - The sink to add. It must implement {@link LoggerSink}.
55
- *
56
- * @throws ({@link BaseError}) - If the sink is already added.
57
- *
58
- * @returns A new Logger instance with the added sink.
65
+ * Resolver for the close promise
59
66
  */
60
- registerSink<Key extends string, Sink extends LoggerSink>(name: Key, sink: Sink): Logger<TSinks & Record<Key, Sink>>;
67
+ private _closeResolver;
61
68
  /**
62
- * Unregister a logging sink.
63
- *
64
- * @template Key - The name of the sink.
65
- *
66
- * @param name - The name of the sink to remove.
67
- *
68
- * @throws ({@link BaseError}) - If the sink is not found.
69
- *
70
- * @returns A new Logger instance without the removed sink.
69
+ * Resolver for backpressure when maxMessagesInFlight is reached
71
70
  */
72
- unregisterSink<Key extends keyof TSinks>(name: Key): Logger<Omit<TSinks, Key>>;
71
+ private _backpressureResolver;
73
72
  /**
74
- * Register multiple sinks at once.
75
- *
76
- * @template TNew - The new sinks to add.
77
- *
78
- * @param sinks - An array of tuples where each tuple contains the sink name and the sink instance.
79
- *
80
- * @throws ({@link BaseError}) - If any sink is already added.
81
- *
82
- * @returns A new Logger instance with the added sinks.
73
+ * Handle the exit event
83
74
  */
84
- registerSinks<TNew extends [string, LoggerSink][] = [string, LoggerSink][]>(sinks: TNew): Logger<TSinks & {
85
- [K in TNew[number][0]]: Extract<TNew[number], [K, LoggerSink]>[1];
86
- }>;
75
+ private readonly _handleExit;
87
76
  /**
88
- * Unregister multiple sinks at once.
89
- *
90
- * @template Keys - The names of the sinks to remove.
91
- *
92
- * @param names - An array of sink names to remove.
93
- *
94
- * @throws ({@link BaseError}) - If any sink is not found.
95
- *
96
- * @returns A new Logger instance without the removed sinks.
77
+ * Handle the worker close event
97
78
  */
98
- unregisterSinks<Keys extends Extract<keyof TSinks, string>>(names: Keys[]): Logger<Omit<TSinks, Keys>>;
79
+ private readonly _handleWorkerClose;
99
80
  /**
100
- * Remove all sinks.
81
+ * Creates a new Logger instance with the specified options.
101
82
  *
102
- * @returns A new Logger instance without any sinks.
83
+ * @param options - Configuration options for the logger
103
84
  */
104
- clearSinks(): Logger;
85
+ constructor(options?: LoggerOptions);
105
86
  /**
106
- * Log an error message.
107
- *
108
- * @template SNames - The names of the sinks to use.
87
+ * Registers a new sink (logging destination) with the logger.
109
88
  *
110
- * @param object - The object to log.
111
- * @param sinksNames - The names of the sinks to use. If not provided, all sinks will be used.
89
+ * @param sinkName - The name of the sink
90
+ * @param sinkConstructor - The sink class constructor
91
+ * @param sinkArgs - The sink constructor arguments
112
92
  *
113
- * @throws ({@link BaseError}) - If no sink is added.
93
+ * @returns The logger instance with new type (for chaining)
114
94
  */
115
- error<SNames extends (keyof TSinks)[] = (keyof TSinks)[]>(object: BodiesIntersection<TSinks, SNames[number]>, sinksNames?: SNames): void;
95
+ registerSink<TSinkName extends string, TSink extends LoggerSink, TSinkArgs extends unknown[]>(sinkName: TSinkName, sinkConstructor: new (...args: TSinkArgs) => TSink, ...sinkArgs: TSinkArgs): Logger<TSinks & Record<TSinkName, new (...args: TSinkArgs) => TSink>>;
116
96
  /**
117
- * Log a warning message.
118
- *
119
- * @template SNames - The names of the sinks to use.
120
- *
121
- * @param object - The object to log.
122
- * @param sinksNames - The names of the sinks to use. If not provided, all sinks will be used.
97
+ * Logs a message at the ERROR level to the specified sinks.
123
98
  *
124
- * @throws ({@link BaseError}) - If no sink is added.
99
+ * @param object - The log message object
100
+ * @param sinkNames - Optional array of sink names to log to; logs to all sinks if omitted
125
101
  */
126
- warn<SNames extends (keyof TSinks)[] = (keyof TSinks)[]>(object: BodiesIntersection<TSinks, SNames[number]>, sinksNames?: SNames): void;
102
+ error<SNames extends (keyof TSinks)[] = (keyof TSinks)[]>(object: SinkBodiesIntersection<TSinks, SNames[number]>, sinkNames?: SNames): void;
127
103
  /**
128
- * Log an info message.
104
+ * Logs a message at the WARN level to the specified sinks.
129
105
  *
130
- * @template SNames - The names of the sinks to use.
131
- *
132
- * @param object - The object to log.
133
- * @param sinksNames - The names of the sinks to use. If not provided, all sinks will be used.
134
- *
135
- * @throws ({@link BaseError}) - If no sink is added.
106
+ * @param object - The log message object
107
+ * @param sinkNames - Optionnal array of sink names to log to; logs to all sinks if omitted
136
108
  */
137
- info<SNames extends (keyof TSinks)[] = (keyof TSinks)[]>(object: BodiesIntersection<TSinks, SNames[number]>, sinksNames?: SNames): void;
109
+ warn<SNames extends (keyof TSinks)[] = (keyof TSinks)[]>(object: SinkBodiesIntersection<TSinks, SNames[number]>, sinkNames?: SNames): void;
138
110
  /**
139
- * Log a debug message.
140
- *
141
- * @template SNames - The names of the sinks to use.
142
- *
143
- * @param object - The object to log.
144
- * @param sinksNames - The names of the sinks to use. If not provided, all sinks will be used.
111
+ * Logs a message at the INFO level to the specified sinks.
145
112
  *
146
- * @throws ({@link BaseError}) - If no sink is added.
113
+ * @param object - The log message object
114
+ * @param sinkNames - Optional array of sink names to log to; logs to all sinks if omitted
147
115
  */
148
- debug<SNames extends (keyof TSinks)[] = (keyof TSinks)[]>(object: BodiesIntersection<TSinks, SNames[number]>, sinksNames?: SNames): void;
116
+ info<SNames extends (keyof TSinks)[] = (keyof TSinks)[]>(object: SinkBodiesIntersection<TSinks, SNames[number]>, sinkNames?: SNames): void;
149
117
  /**
150
- * Log a generic message.
118
+ * Logs a message at the DEBUG level to the specified sinks.
151
119
  *
152
- * @template SNames - The names of the sinks to use.
153
- *
154
- * @param object - The object to log.
155
- * @param sinksNames - The names of the sinks to use. If not provided, all sinks will be used.
156
- *
157
- * @throws ({@link BaseError}) - If no sink is added.
120
+ * @param object - The log message object
121
+ * @param sinkNames - Optional array of sink names to log to; logs to all sinks if omitted
158
122
  */
159
- log<SNames extends (keyof TSinks)[] = (keyof TSinks)[]>(object: BodiesIntersection<TSinks, SNames[number]>, sinksNames?: SNames): void;
123
+ debug<SNames extends (keyof TSinks)[] = (keyof TSinks)[]>(object: SinkBodiesIntersection<TSinks, SNames[number]>, sinkNames?: SNames): void;
160
124
  /**
161
- * Internal: execute all sinks for a log event.
162
- *
163
- * @template TLogObject - The type of the log object.
164
- *
165
- * @param level - The log level.
166
- * @param date - The date of the log event.
167
- * @param object - The object to log.
168
- * @param sinksNames - The names of the sinks to use. If not provided, all sinks will be used.
125
+ * Logs a message at the TRACE level to the specified sinks.
169
126
  *
170
- * @throws ({@link BaseError}) - If a sink throws.
127
+ * @param object - The log message object
128
+ * @param sinkNames - Optional array of sink names to log to; logs to all sinks if omitted
171
129
  */
172
- private _executeStrategies;
130
+ log<SNames extends (keyof TSinks)[] = (keyof TSinks)[]>(object: SinkBodiesIntersection<TSinks, SNames[number]>, sinkNames?: SNames): void;
173
131
  /**
174
- * Internal: queue a log event and start writing if not already.
175
- *
176
- * @template TLogObject - The type of the log object.
177
- *
178
- * @param level - The log level.
179
- * @param object - The object to log.
180
- * @param sinksNames - The names of the sinks to use. If not provided, all sinks will be used.
132
+ * Flushes all pending logs and waits for them to be processed.
133
+ */
134
+ flush(): Promise<void>;
135
+ /**
136
+ * Closes the logger, flushes pending logs, and releases resources.
137
+ */
138
+ close(): Promise<void>;
139
+ /**
140
+ * Enqueues a log message to be processed by the worker.
181
141
  *
182
- * @throws ({@link BaseError}) - If no sink is added.
142
+ * @param level - The log level
143
+ * @param object - The log message object
144
+ * @param sinkNames - Optional array of sink names to log to; logs to all sinks if omitted
145
+ */
146
+ private _enqueue;
147
+ /**
148
+ * Triggers processing of pending logs.
149
+ */
150
+ private _triggerProcessing;
151
+ /**
152
+ * Processes pending log messages by sending them to the worker in batches.
153
+ */
154
+ private _processPendingLogs;
155
+ /**
156
+ * Releases a batch by decrementing the in-flight counter and resolving backpressure if needed.
157
+ */
158
+ private _releaseBatch;
159
+ /**
160
+ * Sets up message handling for the worker.
161
+ */
162
+ private _setupWorkerMessages;
163
+ /**
164
+ * Sets up automatic flushing and closing of the logger on process exit.
183
165
  */
184
- private _out;
166
+ private _setupAutoEnd;
185
167
  /**
186
- * Internal: process the log queue and emit 'end' when done.
168
+ * Handles the beforeExit event.
187
169
  */
188
- private _writeLog;
170
+ private readonly _handleBeforeExit;
189
171
  }
@@ -3,20 +3,6 @@ import type { LoggerSink } from '../../../modules/logger/types/logger-sink';
3
3
  /**
4
4
  * ConsoleLoggerSink implements LoggerSink to provide logging functionality to the console.
5
5
  */
6
- export declare class ConsoleLoggerSink implements LoggerSink {
7
- private readonly _colorize;
8
- /**
9
- * Initializes the ConsoleLoggerSink.
10
- *
11
- * @param colorize - Indicates if the output should be colorized. (Default is false.)
12
- */
13
- constructor(colorize?: boolean);
14
- /**
15
- * Logs a message to the console with the specified log level.
16
- *
17
- * @param level - The log level at which the message should be logged.
18
- * @param date - The date at which the message was logged.
19
- * @param object - The object to log.
20
- */
21
- log(level: LogLevels, date: Date, object: unknown): void;
6
+ export declare class ConsoleLoggerSink<TLogObject = unknown> implements LoggerSink<TLogObject> {
7
+ log(level: LogLevels, timestamp: number, object: TLogObject): Promise<void>;
22
8
  }
@@ -0,0 +1,8 @@
1
+ import type { LoggerSink } from '../../../modules/logger/types/logger-sink';
2
+ /**
3
+ * DevNullLoggerSink implements LoggerSink to discard all logs (like /dev/null).
4
+ * Useful for benchmarking the logger overhead without I/O.
5
+ */
6
+ export declare class DevNullLoggerSink<TLogObject = unknown> implements LoggerSink<TLogObject> {
7
+ log(): void;
8
+ }
@@ -0,0 +1,3 @@
1
+ export declare const FILE_LOGGER_ERROR_KEYS: {
2
+ readonly FAILED_TO_CLOSE_STREAM: "mrx-core.file_logger.error.failed_to_close_stream";
3
+ };
@@ -0,0 +1,25 @@
1
+ import type { LogLevels } from '../../../../modules/logger/types/log-levels';
2
+ import type { LoggerSink } from '../../../../modules/logger/types/logger-sink';
3
+ export interface FileLoggerConfig {
4
+ /**
5
+ * Path to the file to log to.
6
+ */
7
+ path: string;
8
+ /**
9
+ * Buffer size before flushing to disk (default: 16KB)
10
+ * Higher = better throughput, lower = less memory
11
+ */
12
+ bufferSize?: number;
13
+ }
14
+ /**
15
+ * FileLoggerSink implements LoggerSink to provide logging functionality to the file system.
16
+ * Uses a WriteStream for efficient buffered writes (like Pino's sonic-boom).
17
+ */
18
+ export declare class FileLoggerSink<TLogObject = unknown> implements LoggerSink<TLogObject> {
19
+ readonly config: FileLoggerConfig;
20
+ private readonly _stream;
21
+ private _isClosed;
22
+ constructor(config: FileLoggerConfig);
23
+ log(level: LogLevels, timestamp: number, object: TLogObject): Promise<void>;
24
+ close(): Promise<void>;
25
+ }
@@ -1,2 +1,4 @@
1
- export { ConsoleLoggerSink } from './console-logger.ts';
2
- export { FileLoggerSink } from './file-logger.ts';
1
+ export { ConsoleLoggerSink } from './console-logger';
2
+ export { DevNullLoggerSink } from './devnull-logger';
3
+ export { FILE_LOGGER_ERROR_KEYS } from './file-logger/enums/file-logger-error-keys';
4
+ export { FileLoggerSink, type FileLoggerConfig } from './file-logger/file-logger';
@@ -1,44 +1,67 @@
1
1
  // @bun
2
+ import {
3
+ BaseError
4
+ } from "../../../chunk-9cgzhc50.js";
5
+
2
6
  // source/modules/logger/sinks/console-logger.ts
3
7
  class ConsoleLoggerSink {
4
- _colorize;
5
- constructor(colorize = false) {
6
- this._colorize = colorize;
7
- }
8
- log(level, date, object) {
9
- const colors = {
10
- ERROR: "\x1B[31m",
11
- WARN: "\x1B[33m",
12
- INFO: "\x1B[36m",
13
- DEBUG: "\x1B[34m",
14
- LOG: "\x1B[35m"
15
- };
16
- const dateColor = this._colorize ? "\x1B[33m" : "";
17
- const colorReset = this._colorize ? "\x1B[0m" : "";
18
- const logLevelColor = this._colorize ? colors[level] : "";
19
- const sanitizedObject = typeof object === "string" ? object : JSON.stringify(object);
20
- const prefixDate = `[${dateColor}${date.toISOString().replace(/T/, " ").replace(/\..+/, "")}${colorReset}]`;
21
- const message = `${prefixDate} ${logLevelColor}${level}${colorReset} : ${sanitizedObject}`;
22
- console[level.toLowerCase()](message);
8
+ async log(level, timestamp, object) {
9
+ const sanitizedContent = typeof object === "string" ? object : JSON.stringify(object);
10
+ await Bun.write(Bun.stdout, `{"timestamp":${timestamp},"level":"${level}","content":${sanitizedContent}}
11
+ `);
23
12
  }
24
13
  }
25
- // source/modules/logger/sinks/file-logger.ts
26
- import { appendFile } from "fs/promises";
27
-
14
+ // source/modules/logger/sinks/devnull-logger.ts
15
+ class DevNullLoggerSink {
16
+ log() {}
17
+ }
18
+ // source/modules/logger/sinks/file-logger/enums/file-logger-error-keys.ts
19
+ var FILE_LOGGER_ERROR_KEYS = {
20
+ FAILED_TO_CLOSE_STREAM: "mrx-core.file_logger.error.failed_to_close_stream"
21
+ };
22
+ // source/modules/logger/sinks/file-logger/file-logger.ts
23
+ import { createWriteStream } from "fs";
28
24
  class FileLoggerSink {
29
- _path;
30
- constructor(path) {
31
- this._path = path;
25
+ config;
26
+ _stream;
27
+ _isClosed = false;
28
+ constructor(config) {
29
+ this.config = config;
30
+ this._stream = createWriteStream(config.path, {
31
+ flags: "a",
32
+ encoding: "utf8",
33
+ highWaterMark: config.bufferSize ?? 16 * 1024
34
+ });
32
35
  }
33
- async log(level, date, object) {
34
- const prefixDate = `[${date.toISOString().replace(/T/, " ").replace(/\..+/, "")}]`;
35
- const sanitizedObject = typeof object === "string" ? object : JSON.stringify(object);
36
- const message = `${prefixDate} ${level} : ${sanitizedObject}`;
37
- await appendFile(this._path, `${message}
38
- `);
36
+ async log(level, timestamp, object) {
37
+ if (this._isClosed)
38
+ return;
39
+ const sanitizedContent = typeof object === "string" ? object : JSON.stringify(object);
40
+ const message = `{"timestamp":${timestamp},"level":"${level}","content":${sanitizedContent}}
41
+ `;
42
+ const canContinue = this._stream.write(message);
43
+ if (!canContinue)
44
+ await new Promise((resolve) => {
45
+ this._stream.once("drain", resolve);
46
+ });
47
+ }
48
+ async close() {
49
+ if (this._isClosed)
50
+ return;
51
+ this._isClosed = true;
52
+ return new Promise((resolve, reject) => {
53
+ this._stream.end((err) => {
54
+ if (err)
55
+ reject(new BaseError(FILE_LOGGER_ERROR_KEYS.FAILED_TO_CLOSE_STREAM, err.message));
56
+ else
57
+ resolve();
58
+ });
59
+ });
39
60
  }
40
61
  }
41
62
  export {
42
63
  FileLoggerSink,
64
+ FILE_LOGGER_ERROR_KEYS,
65
+ DevNullLoggerSink,
43
66
  ConsoleLoggerSink
44
67
  };
@@ -1,6 +1,6 @@
1
- export type { BodiesIntersection } from './bodies-intersection.ts';
2
- export type { LogLevels } from './log-levels.ts';
3
- export type { LogStreamChunk } from './log-stream-chunk.ts';
4
- export type { LoggerSink } from './logger-sink.ts';
5
- export type { SinkBody } from './sink-body.ts';
6
- export type { SinkMap } from './sink-map.ts';
1
+ export type { LogLevels } from './log-levels';
2
+ export type { LoggerOptions } from './logger-options';
3
+ export type { LoggerSink } from './logger-sink';
4
+ export type { SinkBodiesIntersection } from './sink-bodies-intersection';
5
+ export type { SinkBody } from './sink-body';
6
+ export type { SinkMap } from './sink-map';
@@ -1,4 +1 @@
1
- /**
2
- * The log levels.
3
- */
4
- export type LogLevels = 'ERROR' | 'WARN' | 'INFO' | 'DEBUG' | 'LOG';
1
+ export type LogLevels = 'ERROR' | 'WARN' | 'INFO' | 'DEBUG' | 'LOG' | 'TRACE';
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Configuration options for the Logger instance.
3
+ */
4
+ export interface LoggerOptions {
5
+ /**
6
+ * Maximum number of log messages that can be queued in memory before dropping new logs.
7
+ * @default 10_000
8
+ */
9
+ maxPendingLogs?: number;
10
+ /**
11
+ * Maximum number of messages that can be sent to the worker without acknowledgment.
12
+ * Controls backpressure to prevent overwhelming the worker thread.
13
+ * @default 100
14
+ */
15
+ maxMessagesInFlight?: number;
16
+ /**
17
+ * Maximum number of logs to batch together before sending to the worker.
18
+ * Higher values = better throughput but higher latency.
19
+ * @default 100
20
+ */
21
+ batchSize?: number;
22
+ /**
23
+ * Maximum time in milliseconds to wait before flushing a partial batch.
24
+ * Prevents logs from being delayed indefinitely when batch size is not reached.
25
+ * Set to 0 to disable time-based flushing.
26
+ * @default 0.1 (100 microseconds)
27
+ */
28
+ batchTimeout?: number;
29
+ /**
30
+ * Whether to automatically flush and close the logger when the process exits.
31
+ * When enabled, hooks are installed on `process.on('beforeExit')` and `process.on('exit')`.
32
+ * @default true
33
+ */
34
+ autoEnd?: boolean;
35
+ /**
36
+ * Whether to flush pending logs before the process exits.
37
+ * Only applies when `autoEnd` is true.
38
+ * @default true
39
+ */
40
+ flushOnBeforeExit?: boolean;
41
+ }
@@ -1,11 +1,20 @@
1
1
  import type { LogLevels } from './log-levels';
2
- export interface LoggerSink<TLogObject = unknown> {
2
+ export interface LoggerSink<TLogObject = unknown, TConfig = unknown> {
3
+ /** Optional configuration for the sink */
4
+ readonly config?: TConfig;
3
5
  /**
4
6
  * Logs a message with the sink's implementation.
7
+ * si vous voulez créer votre propre sink vous devrez implémenter cette méthode et tout ce qui est importation doit etre sous forme d'importation dynamique
5
8
  *
6
9
  * @param level - The log level at which the message should be logged.
7
- * @param date - The date at which the message was logged.
10
+ * @param timestamp - The date at which the message was logged.
8
11
  * @param object - The object to log.
9
12
  */
10
- log(level: LogLevels, date: Date, object: TLogObject): Promise<void> | void;
13
+ log(level: LogLevels, timestamp: number, object: TLogObject): Promise<void> | void;
14
+ /**
15
+ * Closes the sink and flushes any pending logs.
16
+ * This method is called when the logger is closing to ensure all resources are properly released.
17
+ * Optional - implement this if your sink needs cleanup (e.g., closing file handles, database connections).
18
+ */
19
+ close?(): Promise<void> | void;
11
20
  }
@@ -0,0 +1,2 @@
1
+ import type { SinkBody } from './sink-body';
2
+ export type SinkBodiesIntersection<TSinks, K extends keyof TSinks> = (K extends unknown ? (object: SinkBody<TSinks, K>) => void : never) extends (object: infer I) => void ? I : never;
@@ -1,2 +1,2 @@
1
1
  import type { LoggerSink } from './logger-sink';
2
- export type SinkBody<TSink, Key extends keyof TSink> = TSink[Key] extends LoggerSink<infer TBody> ? TBody : never;
2
+ export type SinkBody<TSink, Key extends keyof TSink> = TSink[Key] extends new (...args: any[]) => LoggerSink<infer TBody> ? TBody : TSink[Key] extends LoggerSink<infer TBody> ? TBody : never;
@@ -1,2 +1,2 @@
1
1
  import type { LoggerSink } from './logger-sink';
2
- export type SinkMap = Record<string, LoggerSink>;
2
+ export type SinkMap = Record<string, new (...args: any[]) => LoggerSink>;