@decaf-ts/logging 0.10.0 → 0.10.2

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 (100) hide show
  1. package/README.md +298 -171
  2. package/dist/logging.cjs +1 -1
  3. package/dist/logging.cjs.map +1 -1
  4. package/dist/logging.js +1 -1
  5. package/dist/logging.js.map +1 -1
  6. package/lib/LoggedClass.cjs +4 -4
  7. package/lib/LoggedClass.d.ts +4 -4
  8. package/lib/constants.cjs +32 -63
  9. package/lib/constants.d.ts +32 -63
  10. package/lib/constants.js.map +1 -1
  11. package/lib/decorators.cjs +28 -28
  12. package/lib/decorators.d.ts +29 -36
  13. package/lib/decorators.js.map +1 -1
  14. package/lib/environment.cjs +34 -41
  15. package/lib/environment.d.ts +31 -32
  16. package/lib/environment.js.map +1 -1
  17. package/lib/esm/LoggedClass.d.ts +4 -4
  18. package/lib/esm/LoggedClass.js +4 -4
  19. package/lib/esm/constants.d.ts +32 -63
  20. package/lib/esm/constants.js +32 -63
  21. package/lib/esm/constants.js.map +1 -1
  22. package/lib/esm/decorators.d.ts +29 -36
  23. package/lib/esm/decorators.js +28 -28
  24. package/lib/esm/decorators.js.map +1 -1
  25. package/lib/esm/environment.d.ts +31 -32
  26. package/lib/esm/environment.js +34 -41
  27. package/lib/esm/environment.js.map +1 -1
  28. package/lib/esm/filters/LogFilter.d.ts +11 -11
  29. package/lib/esm/filters/LogFilter.js +5 -5
  30. package/lib/esm/filters/PatternFilter.d.ts +15 -15
  31. package/lib/esm/filters/PatternFilter.js +12 -12
  32. package/lib/esm/index.d.ts +2 -2
  33. package/lib/esm/index.js +3 -3
  34. package/lib/esm/logging.d.ts +119 -113
  35. package/lib/esm/logging.js +223 -138
  36. package/lib/esm/logging.js.map +1 -1
  37. package/lib/esm/pino/index.d.ts +6 -0
  38. package/lib/esm/pino/index.js +6 -0
  39. package/lib/esm/pino/index.js.map +1 -1
  40. package/lib/esm/pino/pino.d.ts +13 -5
  41. package/lib/esm/pino/pino.js +70 -124
  42. package/lib/esm/pino/pino.js.map +1 -1
  43. package/lib/esm/text.d.ts +29 -67
  44. package/lib/esm/text.js +29 -67
  45. package/lib/esm/text.js.map +1 -1
  46. package/lib/esm/time.d.ts +45 -43
  47. package/lib/esm/time.js +38 -36
  48. package/lib/esm/time.js.map +1 -1
  49. package/lib/esm/types.d.ts +59 -50
  50. package/lib/esm/utils.d.ts +43 -0
  51. package/lib/esm/utils.js +55 -3
  52. package/lib/esm/utils.js.map +1 -1
  53. package/lib/esm/web.d.ts +2 -2
  54. package/lib/esm/web.js +2 -2
  55. package/lib/esm/winston/index.d.ts +7 -0
  56. package/lib/esm/winston/index.js +7 -1
  57. package/lib/esm/winston/index.js.map +1 -1
  58. package/lib/esm/winston/winston.d.ts +17 -21
  59. package/lib/esm/winston/winston.js +29 -36
  60. package/lib/esm/winston/winston.js.map +1 -1
  61. package/lib/filters/LogFilter.cjs +5 -5
  62. package/lib/filters/LogFilter.d.ts +11 -11
  63. package/lib/filters/PatternFilter.cjs +12 -12
  64. package/lib/filters/PatternFilter.d.ts +15 -15
  65. package/lib/index.cjs +3 -3
  66. package/lib/index.d.ts +2 -2
  67. package/lib/logging.cjs +224 -139
  68. package/lib/logging.d.ts +119 -113
  69. package/lib/logging.js.map +1 -1
  70. package/lib/pino/index.cjs +6 -0
  71. package/lib/pino/index.d.ts +6 -0
  72. package/lib/pino/index.js.map +1 -1
  73. package/lib/pino/pino.cjs +102 -126
  74. package/lib/pino/pino.d.ts +13 -5
  75. package/lib/pino/pino.js.map +1 -1
  76. package/lib/text.cjs +29 -67
  77. package/lib/text.d.ts +29 -67
  78. package/lib/text.js.map +1 -1
  79. package/lib/time.cjs +38 -36
  80. package/lib/time.d.ts +45 -43
  81. package/lib/time.js.map +1 -1
  82. package/lib/types.d.ts +59 -50
  83. package/lib/utils.cjs +55 -3
  84. package/lib/utils.d.ts +43 -0
  85. package/lib/utils.js.map +1 -1
  86. package/lib/web.cjs +2 -2
  87. package/lib/web.d.ts +2 -2
  88. package/lib/winston/index.cjs +22 -0
  89. package/lib/winston/index.d.ts +7 -0
  90. package/lib/winston/index.js.map +1 -1
  91. package/lib/winston/winston.cjs +29 -36
  92. package/lib/winston/winston.d.ts +17 -21
  93. package/lib/winston/winston.js.map +1 -1
  94. package/package.json +9 -10
  95. package/lib/accumulate.types.cjs +0 -27
  96. package/lib/accumulate.types.d.ts +0 -1
  97. package/lib/accumulate.types.js.map +0 -1
  98. package/lib/esm/accumulate.types.d.ts +0 -1
  99. package/lib/esm/accumulate.types.js +0 -25
  100. package/lib/esm/accumulate.types.js.map +0 -1
@@ -1,13 +1,13 @@
1
1
  import { LoggerFactory, LoggingConfig, LoggingContext, StringLike, Theme, Logger } from "./types";
2
2
  import { LogLevel } from "./constants";
3
3
  import { LoggedEnvironment } from "./environment";
4
+ export declare const ROOT_CONTEXT_SYMBOL: unique symbol;
4
5
  /**
5
6
  * @description A minimal logger implementation.
6
- * @summary MiniLogger is a lightweight logging class that implements the Logger interface.
7
- * It provides basic logging functionality with support for different log levels, verbosity,
8
- * context-aware logging, and customizable formatting.
9
- * @param {string} context - The context (typically class name) this logger is associated with
10
- * @param {Partial<LoggingConfig>} conf - Optional configuration to override global settings
7
+ * @summary MiniLogger is a lightweight logging class that implements the Logger interface. It provides basic logging functionality with support for different log levels, verbosity, context-aware logging, and customizable formatting.
8
+ * @param {string} [context] - The context (typically class name) this logger is associated with.
9
+ * @param {Partial<LoggingConfig>} [conf] - Optional configuration to override global settings.
10
+ * @param {string[]} [baseContext=[]] - The base context for the logger.
11
11
  * @class MiniLogger
12
12
  * @example
13
13
  * // Create a new logger for a class
@@ -26,108 +26,113 @@ import { LoggedEnvironment } from "./environment";
26
26
  * logger.for('specialMethod', { style: true }).info('Styled message');
27
27
  */
28
28
  export declare class MiniLogger implements Logger {
29
- protected context: string;
30
29
  protected conf?: Partial<LoggingConfig> | undefined;
31
- constructor(context: string, conf?: Partial<LoggingConfig> | undefined);
30
+ protected context: string[];
31
+ protected baseContext: string[];
32
+ constructor(context?: string, conf?: Partial<LoggingConfig> | undefined, baseContext?: string[]);
32
33
  protected config(key: keyof LoggingConfig): LoggingConfig[keyof LoggingConfig];
33
- for(config: Partial<LoggingConfig>): Logger;
34
+ for(config: Partial<LoggingConfig>): this;
34
35
  for(method: string | ((...args: any[]) => any) | {
35
36
  new (...args: any[]): any;
36
- } | object): Logger;
37
+ } | object): this;
37
38
  for(method: string | ((...args: any[]) => any) | {
38
39
  new (...args: any[]): any;
39
- } | object | Partial<LoggingConfig>, config: Partial<LoggingConfig>, ...args: any[]): Logger;
40
+ } | object | Partial<LoggingConfig>, config: Partial<LoggingConfig>, ...args: any[]): this;
40
41
  /**
41
- * @description Creates a formatted log string
42
- * @summary Generates a log string with timestamp, colored log level, context, and message
43
- * @param {LogLevel} level - The log level for this message
44
- * @param {StringLike | Error} message - The message to log or an Error object
45
- * @param {string} [error] - Optional error to extract stack trace to include in the log
46
- * @return {string} A formatted log string with all components
42
+ * @description Creates a formatted log string.
43
+ * @summary Generates a log string with timestamp, colored log level, context, and message.
44
+ * @param {LogLevel} level - The log level for this message.
45
+ * @param {StringLike | Error} message - The message to log or an Error object.
46
+ * @param {Error} [error] - Optional error to extract stack trace to include in the log.
47
+ * @return {string} A formatted log string with all components.
47
48
  */
48
49
  protected createLog(level: LogLevel, message: StringLike | Error, error?: Error): string;
49
50
  /**
50
- * @description Logs a message with the specified log level
51
- * @summary Checks if the message should be logged based on the current log level,
52
- * then uses the appropriate console method to output the formatted log
53
- * @param {LogLevel} level - The log level of the message
54
- * @param {StringLike | Error} msg - The message to be logged or an Error object
55
- * @param {string} [error] - Optional stack trace to include in the log
51
+ * @description Logs a message with the specified log level.
52
+ * @summary Checks if the message should be logged based on the current log level, then uses the appropriate console method to output the formatted log.
53
+ * @param {LogLevel} level - The log level of the message.
54
+ * @param {StringLike | Error} msg - The message to be logged or an Error object.
55
+ * @param {Error} [error] - Optional stack trace to include in the log.
56
56
  * @return {void}
57
57
  */
58
58
  protected log(level: LogLevel, msg: StringLike | Error, error?: Error): void;
59
59
  /**
60
- * @description Logs a message at the benchmark level
61
- * @summary Logs a message at the benchmark level if the current verbosity setting allows it
62
- * @param {StringLike} msg - The message to be logged
60
+ * @description Logs a message at the benchmark level.
61
+ * @summary Logs a message at the benchmark level if the current verbosity setting allows it.
62
+ * @param {StringLike} msg - The message to be logged.
63
63
  * @return {void}
64
64
  */
65
65
  benchmark(msg: StringLike): void;
66
66
  /**
67
- * @description Logs a message at the silly level
68
- * @summary Logs a message at the silly level if the current verbosity setting allows it
69
- * @param {StringLike} msg - The message to be logged
70
- * @param {number} [verbosity=0] - The verbosity level of the message
67
+ * @description Logs a message at the silly level.
68
+ * @summary Logs a message at the silly level if the current verbosity setting allows it.
69
+ * @param {StringLike} msg - The message to be logged.
70
+ * @param {number} [verbosity=0] - The verbosity level of the message.
71
71
  * @return {void}
72
72
  */
73
73
  silly(msg: StringLike, verbosity?: number): void;
74
74
  /**
75
- * @description Logs a message at the verbose level
76
- * @summary Logs a message at the verbose level if the current verbosity setting allows it
77
- * @param {StringLike} msg - The message to be logged
78
- * @param {number} [verbosity=0] - The verbosity level of the message
75
+ * @description Logs a message at the verbose level.
76
+ * @summary Logs a message at the verbose level if the current verbosity setting allows it.
77
+ * @param {StringLike} msg - The message to be logged.
78
+ * @param {number} [verbosity=0] - The verbosity level of the message.
79
79
  * @return {void}
80
80
  */
81
81
  verbose(msg: StringLike, verbosity?: number): void;
82
82
  /**
83
- * @description Logs a message at the info level
84
- * @summary Logs a message at the info level for general application information
85
- * @param {StringLike} msg - The message to be logged
83
+ * @description Logs a message at the info level.
84
+ * @summary Logs a message at the info level for general application information.
85
+ * @param {StringLike} msg - The message to be logged.
86
86
  * @return {void}
87
87
  */
88
88
  info(msg: StringLike): void;
89
89
  /**
90
- * @description Logs a message at the debug level
91
- * @summary Logs a message at the debug level for detailed troubleshooting information
92
- * @param {StringLike} msg - The message to be logged
90
+ * @description Logs a message at the debug level.
91
+ * @summary Logs a message at the debug level for detailed troubleshooting information.
92
+ * @param {StringLike} msg - The message to be logged.
93
93
  * @return {void}
94
94
  */
95
95
  debug(msg: StringLike): void;
96
96
  /**
97
- * @description Logs a message at the error level
98
- * @summary Logs a message at the error level for errors and exceptions
99
- * @param {StringLike | Error} msg - The message to be logged or an Error object
100
- * @param e
97
+ * @description Logs a message at the error level.
98
+ * @summary Logs a message at the error level for errors and exceptions.
99
+ * @param {StringLike | Error} msg - The message to be logged or an Error object.
100
+ * @param {Error} [e] - Optional error to include in the log.
101
101
  * @return {void}
102
102
  */
103
103
  error(msg: StringLike | Error, e?: Error): void;
104
104
  /**
105
- * @description Logs a message at the error level
106
- * @summary Logs a message at the error level for errors and exceptions
107
- * @param {StringLike} msg - The message to be logged or an Error object
105
+ * @description Logs a message at the warning level.
106
+ * @summary Logs a message at the warning level for potential issues.
107
+ * @param {StringLike} msg - The message to be logged.
108
108
  * @return {void}
109
109
  */
110
110
  warn(msg: StringLike): void;
111
111
  /**
112
- * @description Logs a message at the error level
113
- * @summary Logs a message at the error level for errors and exceptions
114
- * @param {StringLike} msg - The message to be logged or an Error object
112
+ * @description Logs a message at the trace level.
113
+ * @summary Logs a message at the trace level for tracing code execution.
114
+ * @param {StringLike} msg - The message to be logged.
115
115
  * @return {void}
116
116
  */
117
117
  trace(msg: StringLike): void;
118
118
  /**
119
- * @description Updates the logger configuration
120
- * @summary Merges the provided configuration with the existing configuration
121
- * @param {Partial<LoggingConfig>} config - The configuration options to apply
119
+ * @description Updates the logger configuration.
120
+ * @summary Merges the provided configuration with the existing configuration.
121
+ * @param {Partial<LoggingConfig>} config - The configuration options to apply.
122
122
  * @return {void}
123
123
  */
124
124
  setConfig(config: Partial<LoggingConfig>): void;
125
+ get root(): string[];
126
+ /**
127
+ * @description Clears any contextual overrides applied by `for`.
128
+ * @summary Returns the same logger instance so more contexts can be chained afterwards.
129
+ * @return {this} The same logger instance.
130
+ */
131
+ clear(): this;
125
132
  }
126
133
  /**
127
- * @description A static class for managing logging operations
128
- * @summary The Logging class provides a centralized logging mechanism with support for
129
- * different log levels, verbosity, and styling. It uses a singleton pattern to maintain a global
130
- * logger instance and allows creating specific loggers for different classes and methods.
134
+ * @description A static class for managing logging operations.
135
+ * @summary The Logging class provides a centralized logging mechanism with support for different log levels, verbosity, and styling. It uses a singleton pattern to maintain a global logger instance and allows creating specific loggers for different classes and methods.
131
136
  * @class Logging
132
137
  * @example
133
138
  * // Set global configuration
@@ -190,128 +195,129 @@ export declare class MiniLogger implements Logger {
190
195
  */
191
196
  export declare class Logging {
192
197
  /**
193
- * @description The global logger instance
194
- * @summary A singleton instance of Logger used for global logging
198
+ * @description The global logger instance.
199
+ * @summary A singleton instance of Logger used for global logging.
195
200
  */
196
201
  private static global?;
197
202
  /**
198
- * @description Factory function for creating logger instances
203
+ * @description Factory function for creating logger instances.
199
204
  * @summary A function that creates new Logger instances. By default, it creates a MiniLogger.
200
205
  */
201
206
  private static _factory;
202
207
  private static _config;
203
208
  private constructor();
204
209
  /**
205
- * @description Sets the factory function for creating logger instances
206
- * @summary Allows customizing how logger instances are created
207
- * @param {LoggerFactory} factory - The factory function to use for creating loggers
210
+ * @description Sets the factory function for creating logger instances.
211
+ * @summary Allows customizing how logger instances are created.
212
+ * @param {LoggerFactory} factory - The factory function to use for creating loggers.
208
213
  * @return {void}
209
214
  */
210
215
  static setFactory(factory: LoggerFactory): void;
211
216
  /**
212
- * @description Updates the global logging configuration
213
- * @summary Allows updating the global logging configuration with new settings
214
- * @param {Partial<LoggingConfig>} config - The configuration options to apply
217
+ * @description Updates the global logging configuration.
218
+ * @summary Allows updating the global logging configuration with new settings.
219
+ * @param {Partial<LoggingConfig>} config - The configuration options to apply.
215
220
  * @return {void}
216
221
  */
217
222
  static setConfig(config: Partial<LoggingConfig>): void;
218
223
  /**
219
- * @description Gets a copy of the current global logging configuration
220
- * @summary Returns a copy of the current global logging configuration
221
- * @return {LoggingConfig} A copy of the current configuration
224
+ * @description Gets a copy of the current global logging configuration.
225
+ * @summary Returns a copy of the current global logging configuration.
226
+ * @return {LoggingConfig} A copy of the current configuration.
222
227
  */
223
228
  static getConfig(): typeof LoggedEnvironment;
224
229
  /**
225
230
  * @description Retrieves or creates the global logger instance.
226
231
  * @summary Returns the existing global logger or creates a new one if it doesn't exist.
227
- *
228
- * @return The global VerbosityLogger instance.
232
+ * @return {Logger} The global Logger instance.
229
233
  */
230
234
  static get(): Logger;
231
235
  /**
232
236
  * @description Logs a verbose message.
233
237
  * @summary Delegates the verbose logging to the global logger instance.
234
- *
235
- * @param msg - The message to be logged.
236
- * @param verbosity - The verbosity level of the message (default: 0).
238
+ * @param {StringLike} msg - The message to be logged.
239
+ * @param {number} [verbosity=0] - The verbosity level of the message.
240
+ * @return {void}
237
241
  */
238
242
  static verbose(msg: StringLike, verbosity?: number): void;
239
243
  /**
240
244
  * @description Logs an info message.
241
245
  * @summary Delegates the info logging to the global logger instance.
242
- *
243
- * @param msg - The message to be logged.
246
+ * @param {StringLike} msg - The message to be logged.
247
+ * @return {void}
244
248
  */
245
249
  static info(msg: StringLike): void;
246
250
  /**
247
- * @description Logs an info message.
248
- * @summary Delegates the info logging to the global logger instance.
249
- *
250
- * @param msg - The message to be logged.
251
+ * @description Logs a trace message.
252
+ * @summary Delegates the trace logging to the global logger instance.
253
+ * @param {StringLike} msg - The message to be logged.
254
+ * @return {void}
251
255
  */
252
256
  static trace(msg: StringLike): void;
253
257
  /**
254
258
  * @description Logs a debug message.
255
259
  * @summary Delegates the debug logging to the global logger instance.
256
- *
257
- * @param msg - The message to be logged.
260
+ * @param {StringLike} msg - The message to be logged.
261
+ * @return {void}
258
262
  */
259
263
  static debug(msg: StringLike): void;
260
264
  /**
261
265
  * @description Logs a benchmark message.
262
266
  * @summary Delegates the benchmark logging to the global logger instance.
263
- *
264
- * @param msg - The message to be logged.
267
+ * @param {StringLike} msg - The message to be logged.
268
+ * @return {void}
265
269
  */
266
270
  static benchmark(msg: StringLike): void;
267
271
  /**
268
272
  * @description Logs a silly message.
269
- * @summary Delegates the debug logging to the global logger instance.
270
- *
271
- * @param msg - The message to be logged.
273
+ * @summary Delegates the silly logging to the global logger instance.
274
+ * @param {StringLike} msg - The message to be logged.
275
+ * @return {void}
272
276
  */
273
277
  static silly(msg: StringLike): void;
274
278
  /**
275
- * @description Logs a silly message.
276
- * @summary Delegates the debug logging to the global logger instance.
277
- *
278
- * @param msg - The message to be logged.
279
+ * @description Logs a warning message.
280
+ * @summary Delegates the warning logging to the global logger instance.
281
+ * @param {StringLike} msg - The message to be logged.
282
+ * @return {void}
279
283
  */
280
284
  static warn(msg: StringLike): void;
281
285
  /**
282
286
  * @description Logs an error message.
283
287
  * @summary Delegates the error logging to the global logger instance.
284
- *
285
- * @param msg - The message to be logged.
286
- * @param e
288
+ * @param {StringLike | Error} msg - The message to be logged.
289
+ * @param {Error} [e] - Optional error to include in the log.
290
+ * @return {void}
287
291
  */
288
- static error(msg: StringLike, e?: Error): void;
292
+ static error(msg: StringLike | Error, e?: Error): void;
289
293
  /**
290
- * @description Creates a logger for a specific object or context
291
- * @summary Creates a new logger instance for the given object or context using the factory function
292
- * @param {LoggingContext} object - The object, class, or context to create a logger for
293
- * @param {Partial<LoggingConfig>} [config] - Optional configuration to override global settings
294
- * @param {...any} args - Additional arguments to pass to the logger factory
295
- * @return {Logger} A new logger instance for the specified object or context
294
+ * @description Creates a logger for a specific object or context.
295
+ * @summary Creates a new logger instance for the given object or context using the factory function.
296
+ * @param {LoggingContext} object - The object, class, or context to create a logger for.
297
+ * @param {Partial<LoggingConfig>} [config] - Optional configuration to override global settings.
298
+ * @param {...any} args - Additional arguments to pass to the logger factory.
299
+ * @return {Logger} A new logger instance for the specified object or context.
296
300
  */
297
301
  static for(object: LoggingContext, config?: Partial<LoggingConfig>, ...args: any[]): Logger;
298
302
  /**
299
- * @description Creates a logger for a specific reason or correlation context
300
- * @summary Utility to quickly create a logger labeled with a free-form reason and optional identifier
301
- * so that ad-hoc operations can be traced without tying the logger to a class or method name.
302
- * @param {string} reason - A textual reason or context label for this logger instance
303
- * @param {string} [id] - Optional identifier to help correlate related log entries
304
- * @return {Logger} A new logger instance labeled with the provided reason and id
303
+ * @description Creates a logger for a specific reason or correlation context.
304
+ * @summary Utility to quickly create a logger labeled with a free-form reason and optional identifier so that ad-hoc operations can be traced without tying the logger to a class or method name.
305
+ * @param {string} reason - A textual reason or context label for this logger instance.
306
+ * @param {string} [id] - Optional identifier to help correlate related log entries.
307
+ * @return {Logger} A new logger instance labeled with the provided reason and id.
305
308
  */
306
309
  static because(reason: string, id?: string): Logger;
310
+ private static baseContext;
311
+ private static attachRootContext;
312
+ private static ensureRoot;
307
313
  /**
308
- * @description Applies theme styling to text
309
- * @summary Applies styling (colors, formatting) to text based on the theme configuration
310
- * @param {string} text - The text to style
311
- * @param {string} type - The type of element to style (e.g., "class", "message", "logLevel")
312
- * @param {LogLevel} loggerLevel - The log level to use for styling
313
- * @param {Theme} [template=DefaultTheme] - The theme to use for styling
314
- * @return {string} The styled text
314
+ * @description Applies theme styling to text.
315
+ * @summary Applies styling (colors, formatting) to text based on the theme configuration.
316
+ * @param {string} text - The text to style.
317
+ * @param type - The type of element to style (e.g., "class", "message", "logLevel").
318
+ * @param {LogLevel} loggerLevel - The log level to use for styling.
319
+ * @param {Theme} [template=DefaultTheme] - The theme to use for styling.
320
+ * @return {string} The styled text.
315
321
  * @mermaid
316
322
  * sequenceDiagram
317
323
  * participant Caller