All files / src/logger definition.ts

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
/**
 * The possible levels for the Logger, inspired by RFC5424, with an additional 'trace' level for ultra-detailed logging.
 *
 * The severity levels are assumed to be numerically ascending from most important to least important.
 *
 * Level descriptions:
 *
 * ```
 * trace     - Extremely detailed debugging information (e.g., per-iteration or per-call tracing)
 * debug     - Detailed debugging information (e.g., function entry/exit points)
 * info      - General informational messages (e.g., operation progress updates)
 * notice    - Normal but significant events (e.g., configuration changes)
 * warning   - Warning conditions (e.g., deprecated feature usage)
 * error     - Error conditions (e.g., operation failures)
 * critical  - Critical conditions (e.g., system component failures)
 * alert     - Action must be taken immediately (e.g., data corruption detected)
 * emergency - System is unusable (e.g., complete system failure)
 * ```
 */
export type LogLevel = 'trace' | 'debug' | 'info' | 'notice' | 'warning' | 'error' | 'critical' | 'alert' | 'emergency';
 
/**
 * Type representing the content of a log entry. Can be a primitive value or a function that returns a primitive value.
 */
export type LogMessage = string | number | boolean | (() => string | number | boolean);
 
/**
 * Type representing the template strings of a log entry. Can be a TemplateStringsArray or a function that returns a
 * TemplateStringsArray.
 */
export type LogTemplateStringsArray = TemplateStringsArray | (() => TemplateStringsArray);
 
/**
 * Generic logger interface that provides methods for logging entries at different severity levels.
 *
 * The logger supports a filtering mechanism based on severity levels:
 *
 * - Each logger has a configurable `level` property which sets the minimum severity level for emitted logs
 * - Log entries with a severity level below the logger's configured level are filtered out
 * - When set to 'off', no log entries are emitted regardless of their level
 *
 * The severity filtering follows this hierarchy (from lowest to highest): debug < info < notice < warning < error <
 * critical < alert < emergency
 *
 * For example, if the logger's level is set to 'warning':
 *
 * - Entries logged with debug(), info(), or notice() methods will be filtered out
 * - Entries logged with warning(), error(), critical(), alert(), or emergency() will be emitted
 */
export interface Logger {
  /**
   * The current minimum severity level of the logger.
   *
   * Log entries with a level below this threshold will not be emitted. For example, setting the level to `info` (which
   * is the default level) will cause `debug` logs to be ignored.
   *
   * If set to 'off', no log entries are emitted regardless of level.
   */
  readonly level: LogLevel | 'off';
 
  /**
   * Sets additional arguments to be included with the next log entry. This is particularly useful with the template
   * string method, because it enables fluent chaining while still passing additional arguments.
   *
   * @example
   *
   * ```ts
   * // Pass an error object with a template literal
   * logger.args(error).e`Failed to connect to database at ${timestamp}`;
   *
   * // Pass multiple arguments
   * logger.args(user, requestId, timestamp).i`User ${user.name} logged in`;
   *
   * // Pass contextual data
   * logger.args({ userId, requestId }).d`Processing request for item ${itemId}`;
   * ```
   *
   * @param args Arguments to be included with the next log entry
   * @returns A logger instance for chaining with template literal methods
   */
  readonly args: (...args: unknown[]) => Logger;
 
  /**
   * Logs a trace-level entry for extremely detailed debugging information (e.g., per-iteration or call tracing).
   *
   * Trace entries are only emitted if the logger's level is set to `trace`.
   *
   * The entry content can be either a direct value or a function that returns a value. Using a function is recommended
   * when the content is expensive to construct, as the function will only be invoked if the entry will actually be
   * emitted based on the current logger level.
   *
   * @example
   *
   * ```ts
   * logger.trace('Loop iteration start');
   * logger.trace(() => `Iteration ${i} state: ${JSON.stringify(state)}`);
   * ```
   *
   * @param message The entry content or function that returns the content
   * @param args Additional arguments to include in the log entry
   */
  readonly trace: (message: LogMessage, ...args: unknown[]) => void;
 
  /**
   * Logs a trace-level entry using a template string, which is only computed if the current log level (`logger.level`)
   * is `trace`.
   *
   * Values in template literals are automatically formatted:
   *
   * - Error objects will show their message text (e.g., `${new Error('fail')}` becomes 'fail')
   * - Objects with a `message` property will display that message
   * - Functions are executed and their return values formatted
   * - All other values are converted to their string representation
   *
   * @example
   *
   * ```ts
   * logger.t`Entering loop body`;
   * logger.t`Iteration ${i} with state: ${state}`;
   * ```
   *
   * @param strings The template strings
   * @param values The values to be interpolated into the template
   */
  readonly t: (strings: LogTemplateStringsArray, ...values: unknown[]) => void;
 
  /**
   * Logs a debug-level entry for detailed debugging information (e.g., function entry/exit points).
   *
   * Debug entries are only emitted if the logger's level is set to `debug` or `trace`.
   *
   * The entry content can be either a direct value or a function that returns a value. Using a function is recommended
   * when the content is expensive to construct, as the function will only be invoked if the entry will actually be
   * emitted based on the current logger level.
   *
   * @example
   *
   * ```ts
   * logger.debug('This is a debug entry');
   * logger.debug(() => `Debug entry with computed value: ${expensiveOperation()}`);
   * ```
   *
   * @param message The entry content or function that returns the content
   * @param args Additional arguments to include in the log entry
   */
  readonly debug: (message: LogMessage, ...args: unknown[]) => void;
 
  /**
   * Logs a debug-level entry using a template string, which is only computed if the current log level (`logger.level`)
   * is `debug` or `trace`.
   *
   * Values in template literals are automatically formatted:
   *
   * - Error objects will show their message text (e.g., `${new Error('Connection failed')}` becomes 'Connection failed')
   * - Objects with a `message` property will display that message
   * - Functions are executed and their return values formatted using the rules above
   * - All other values are converted to their string representation
   *
   * @example
   *
   * ```ts
   * // Basic template literal
   * logger.d`Debug entry with simple text`;
   *
   * // With computed values
   * logger.d`Debug entry with computed value: ${expensiveOperation()}`;
   *
   * // With error objects - message is automatically extracted
   * const error = new Error('Something went wrong');
   * logger.d`Operation failed: ${error}`; // Logs: "Operation failed: Something went wrong"
   * ```
   *
   * @param strings The template strings
   * @param values The values to be interpolated into the template
   */
  readonly d: (strings: LogTemplateStringsArray, ...values: unknown[]) => void;
 
  /**
   * Logs an info-level entry for general informational messages (e.g., operation progress updates).
   *
   * Info entries are only emitted if the logger's level is set to `info`, `debug`, or `trace`.
   *
   * The entry content can be either a direct value or a function that returns a value. Using a function is recommended
   * when the message is expensive to construct, as the function will only be invoked if the entry will actually be
   * emitted based on the current logger level.
   *
   * @example
   *
   * ```ts
   * logger.info('Operation started');
   * logger.info(() => `Processing item ${itemId} at ${new Date().toISOString()}`);
   * ```
   *
   * @param message The entry content or function that returns the content
   * @param args Additional arguments to include in the log entry
   */
  readonly info: (message: LogMessage, ...args: unknown[]) => void;
 
  /**
   * Logs an info-level entry using a template string, which is only computed if the current log level (`logger.level`)
   * is `info`, `debug`, or `trace`.
   *
   * Values in template literals are automatically formatted:
   *
   * - Error objects will show their message text (e.g., `${new Error('Connection failed')}` becomes 'Connection failed')
   * - Objects with a `message` property will display that message
   * - Functions are executed and their return values formatted using the rules above
   * - All other values are converted to their string representation
   *
   * @example
   *
   * ```ts
   * // Basic template literal
   * logger.i`Operation started`;
   *
   * // With computed values
   * logger.i`Processing item ${itemId} at ${new Date().toISOString()}`;
   *
   * // With error objects - message is automatically extracted
   * const error = new Error('Missing configuration');
   * logger.i`Config status: ${error}`; // Logs: "Config status: Missing configuration"
   * ```
   *
   * @param strings The template strings
   * @param values The values to be interpolated into the template
   */
  readonly i: (strings: LogTemplateStringsArray, ...values: unknown[]) => void;
 
  /**
   * Logs a notice-level entry for normal but significant events (e.g., configuration changes).
   *
   * Notice entries are only emitted if the logger's level is set to `notice`, `info`, `debug`, or `trace`.
   *
   * The entry content can be either a direct value or a function that returns a value. Using a function is recommended
   * when the message is expensive to construct, as the function will only be invoked if the entry will actually be
   * emitted based on the current logger level.
   *
   * @example
   *
   * ```ts
   * logger.notice('Configuration updated');
   * logger.notice(() => `User ${userId} changed settings at ${new Date().toISOString()}`);
   * ```
   *
   * @param message The entry content or function that returns the content
   * @param args Additional arguments to include in the log entry
   */
  readonly notice: (message: LogMessage, ...args: unknown[]) => void;
 
  /**
   * Logs a notice-level entry using a template string, which is only computed if the current log level (`logger.level`)
   * is `notice`, `info`, `debug`, or `trace`.
   *
   * Values in template literals are automatically formatted:
   *
   * - Error objects will show their message text (e.g., `${new Error('Connection failed')}` becomes 'Connection failed')
   * - Objects with a `message` property will display that message
   * - Functions are executed and their return values formatted using the rules above
   * - All other values are converted to their string representation
   *
   * @example
   *
   * ```ts
   * // Basic template literal
   * logger.n`Configuration updated`;
   *
   * // With computed values
   * logger.n`User ${userId} changed settings at ${new Date().toISOString()}`;
   *
   * // With error objects - message is automatically extracted
   * const warningObj = { message: 'Almost reached quota' };
   * logger.n`Usage warning: ${warningObj}`; // Logs: "Usage warning: Almost reached quota"
   * ```
   *
   * @param strings The template strings
   * @param values The values to be interpolated into the template
   */
  readonly n: (strings: LogTemplateStringsArray, ...values: unknown[]) => void;
 
  /**
   * Logs a warning-level entry for warning conditions (e.g., deprecated feature usage).
   *
   * Warning entries are only emitted if the logger's level is set to `warning`, `notice`, `info`, `debug`, or `trace`.
   *
   * The entry content can be either a direct value or a function that returns a value. Using a function is recommended
   * when the message is expensive to construct, as the function will only be invoked if the entry will actually be
   * emitted based on the current logger level.
   *
   * The warning entry content can be:
   *
   * - A direct value that is logged as is,
   * - A function that returns a value, useful for messages that are expensive to compute,
   * - An Error object, which is automatically stringified and added as an additional argument,
   * - An object with an `error` property that is logged as a string and added as an additional argument - use this
   *   whenever logging an error of type unknown.
   *
   * @example
   *
   * ```ts
   * logger.warning('Feature X is deprecated and will be removed in version 2.0');
   * logger.warning(() => `Slow operation detected: ${operation} took ${duration}ms`);
   * logger.warning(new Error('Connection timeout... Retrying...'), error);
   * logger.warning({ error: ['Connection timeout... Retrying...', errorCode] });
   * ```
   *
   * @param input The entry content or function that returns the content
   * @param args Additional arguments to include in the log entry
   */
  readonly warning: (input: LogMessage | Error | { error: unknown }, ...args: unknown[]) => void;
 
  /**
   * Logs a warning-level entry using a template string, which is only computed if the current log level
   * (`logger.level`) is `warning`, `notice`, `info`, `debug`, or `trace`.
   *
   * Values in template literals are automatically formatted:
   *
   * - Error objects will show their message text (e.g., `${new Error('Connection failed')}` becomes 'Connection failed')
   * - Objects with a `message` property will display that message
   * - Functions are executed and their return values formatted using the rules above
   * - All other values are converted to their string representation
   *
   * @example
   *
   * ```ts
   * // Basic template literal
   * logger.w`Feature X is deprecated and will be removed in version 2.0`;
   *
   * // With computed values
   * logger.w`Slow operation detected: ${operation} took ${duration}ms`;
   *
   * // With error objects - message is automatically extracted
   * const deprecationError = new Error('API version will be removed soon');
   * logger.w`API usage warning: ${deprecationError}`; // Logs: "API usage warning: API version will be removed soon"
   * ```
   *
   * @param strings The template strings
   * @param values The values to be interpolated into the template
   */
  readonly w: (strings: LogTemplateStringsArray, ...values: unknown[]) => void;
 
  /**
   * Logs an error-level entry for error conditions (e.g., operation failures).
   *
   * Error entries are only emitted if the logger's level is set to `error`, `warning`, `notice`, `info`, `debug`, or
   * `trace`.
   *
   * The error entry content can be:
   *
   * - A direct value that is logged as is,
   * - A function that returns a value, useful for messages that are expensive to compute,
   * - An Error object, which is automatically stringified and added as an additional argument,
   * - An object with an `error` property that is logged as a string and added as an additional argument - use this
   *   whenever logging an error of type unknown.
   *
   * @example
   *
   * ```ts
   * logger.error('Failed to connect to database');
   * logger.error(() => `Operation failed at ${new Date().toISOString()}`);
   * logger.error(new Error('Connection timeout'), error);
   * logger.error({ error: ['Database connection failed', errorCode] });
   * ```
   *
   * @param input The error content, Error object, or function that returns content
   * @param args Additional arguments to include in the log entry
   */
  readonly error: (input: LogMessage | Error | { error: unknown }, ...args: unknown[]) => void;
 
  /**
   * Logs an error-level entry using a template string, which is only computed if the current log level (`logger.level`)
   * is `error`, `warning`, `notice`, `info`, `debug`, or `trace`.
   *
   * Values in template literals are automatically formatted:
   *
   * - Error objects will show their message text (e.g., `${new Error('Connection failed')}` becomes 'Connection failed')
   * - Objects with a `message` property will display that message
   * - Functions are executed and their return values formatted using the rules above
   * - All other values are converted to their string representation
   *
   * @example
   *
   * ```ts
   * // Basic template literal
   * logger.e`Failed to connect to database`;
   *
   * // With automatic date formatting
   * logger.e`Operation failed at ${new Date()}`;
   *
   * // With error objects - message is automatically extracted
   * const error = new Error('Connection timeout');
   * logger.e`Database error: ${error}`; // Logs: "Database error: Connection timeout"
   *
   * // Combined with args() to include the error object in the log
   * logger.args(error).e`An error occurred while performing the operation: ${error}`;
   * ```
   *
   * @param strings The template strings
   * @param values The values to be interpolated into the template
   */
  readonly e: (strings: LogTemplateStringsArray, ...values: unknown[]) => void;
 
  /**
   * Logs a critical-level entry for critical conditions (e.g., system component failures).
   *
   * Critical entries are only emitted if the logger's level is set to `critical`, `error`, `warning`, `notice`, `info`,
   * , `debug`, or `trace`.
   *
   * The critical entry content can be:
   *
   * - A direct value that is logged as is,
   * - A function that returns a value, useful for messages that are expensive to compute,
   * - An Error object, which is automatically stringified and added as an additional argument,
   * - An object with an `error` property that is logged as a string and added as an additional argument - use this
   *   whenever logging an error of type unknown.
   *
   * @example
   *
   * ```ts
   * logger.critical('Database connection pool exhausted');
   * logger.critical(() => `System memory usage critical: ${memoryUsage}%`);
   * logger.critical(new Error('Connection timeout'), error);
   * logger.critical({ error: ['Database connection failed', errorCode] });
   * ```
   *
   * @param input The entry content or function that returns the content
   * @param args Additional arguments to include in the log entry
   */
  readonly critical: (input: LogMessage | Error | { error: unknown }, ...args: unknown[]) => void;
 
  /**
   * Logs a critical-level entry using a template string, which is only computed if the current log level
   * (`logger.level`) is `critical`, `error`, `warning`, `notice`, `info`, `debug`, or `trace`.
   *
   * Values in template literals are automatically formatted:
   *
   * - Error objects will show their message text (e.g., `${new Error('Connection failed')}` becomes 'Connection failed')
   * - Objects with a `message` property will display that message
   * - Functions are executed and their return values formatted using the rules above
   * - All other values are converted to their string representation
   *
   * @example
   *
   * ```ts
   * // Basic template literal
   * logger.c`Database connection pool exhausted`;
   *
   * // With computed values
   * logger.c`System memory usage critical: ${memoryUsage}%`;
   *
   * // With error objects - message is automatically extracted
   * const criticalError = new Error('Connection pool saturated');
   * logger.c`Resource exhaustion: ${criticalError}`; // Logs: "Resource exhaustion: Connection pool saturated"
   * ```
   *
   * @param strings The template strings
   * @param values The values to be interpolated into the template
   */
  readonly c: (strings: LogTemplateStringsArray, ...values: unknown[]) => void;
 
  /**
   * Logs an alert-level entry for conditions where action must be taken immediately (e.g., data corruption detected).
   *
   * Alert entries are only emitted if the logger's level is set to `alert`, `critical`, `error`, `warning`, `notice`,
   * `info`, `debug`, or `trace`.
   *
   * The alert entry content can be:
   *
   * - A direct value that is logged as is,
   * - A function that returns a value, useful for messages that are expensive to compute,
   * - An Error object, which is automatically stringified and added as an additional argument,
   * - An object with an `error` property that is logged as a string and added as an additional argument - use this
   *   whenever logging an error of type unknown.
   *
   * @example
   *
   * ```ts
   * logger.alert('Data corruption detected in customer database');
   * logger.alert(() => `Security breach detected from IP ${ipAddress}`);
   * logger.alert(new Error('Connection timeout'), error);
   * logger.alert({ error: ['Database connection failed', errorCode] });
   * ```
   *
   * @param input The entry content or function that returns the content
   * @param args Additional arguments to include in the log entry
   */
  readonly alert: (input: LogMessage | Error | { error: unknown }, ...args: unknown[]) => void;
 
  /**
   * Logs an alert-level entry using a template string, which is only computed if the current log level (`logger.level`)
   * is `alert`, `critical`, `error`, `warning`, `notice`, `info`, `debug`, or `trace`.
   *
   * Values in template literals are automatically formatted:
   *
   * - Error objects will show their message text (e.g., `${new Error('Connection failed')}` becomes 'Connection failed')
   * - Objects with a `message` property will display that message
   * - Functions are executed and their return values formatted using the rules above
   * - All other values are converted to their string representation
   *
   * @example
   *
   * ```ts
   * // Basic template literal
   * logger.a`Data corruption detected in customer database`;
   *
   * // With computed values
   * logger.a`Security breach detected from IP ${ipAddress}`;
   *
   * // With error objects - message is automatically extracted
   * const securityError = new Error('Unauthorized access detected');
   * logger.a`Security alert: ${securityError}`; // Logs: "Security alert: Unauthorized access detected"
   * ```
   *
   * @param strings The template strings
   * @param values The values to be interpolated into the template
   */
  readonly a: (strings: LogTemplateStringsArray, ...values: unknown[]) => void;
 
  /**
   * Logs an emergency-level entry for when the system is unusable (e.g., complete system failure).
   *
   * Emergency entries are emitted at all logger levels except when the logger level is set to 'off'.
   *
   * The emergency entry content can be:
   *
   * - A direct value that is logged as is,
   * - A function that returns a value, useful for messages that are expensive to compute,
   * - An Error object, which is automatically stringified and added as an additional argument,
   * - An object with an `error` property that is logged as a string and added as an additional argument - use this
   *   whenever logging an error of type unknown.
   *
   * @example
   *
   * ```ts
   * logger.emergency('System is shutting down due to critical failure');
   * logger.emergency(() => `Fatal error in primary system: ${errorDetails}`);
   * logger.emergency(new Error('Connection timeout'), error);
   * logger.emergency({ error: ['Database connection failed', errorCode] });
   * ```
   *
   * @param input The entry content or function that returns the content
   * @param args Additional arguments to include in the log entry
   */
  readonly emergency: (input: LogMessage | Error | { error: unknown }, ...args: unknown[]) => void;
 
  /**
   * Logs an emergency-level entry using a template string, which is computed at all logger levels except 'off'.
   *
   * Values in template literals are automatically formatted:
   *
   * - Error objects will show their message text (e.g., `${new Error('Connection failed')}` becomes 'Connection failed')
   * - Objects with a `message` property will display that message
   * - Functions are executed and their return values formatted using the rules above
   * - All other values are converted to their string representation
   *
   * @example
   *
   * ```ts
   * // Basic template literal
   * logger.em`System is shutting down due to critical failure`;
   *
   * // With computed values
   * logger.em`Fatal error in primary system: ${errorDetails}`;
   *
   * // With error objects - message is automatically extracted
   * const fatalError = new Error('Catastrophic failure in database cluster');
   * logger.em`EMERGENCY: ${fatalError}`; // Logs: "EMERGENCY: Catastrophic failure in database cluster"
   * ```
   *
   * @param strings The template strings
   * @param values The values to be interpolated into the template
   */
  readonly em: (strings: LogTemplateStringsArray, ...values: unknown[]) => void;
 
  /**
   * Logs an entry at a specific severity level. This method is useful for dynamically setting the level without having
   * to call the specific level method directly.
   *
   * The entry content can be either a direct value or a function that returns a value. Using a function is recommended
   * when the message is expensive to construct, as the function will only be invoked if the entry will actually be
   * emitted based on the current logger level.
   *
   * @example
   *
   * ```ts
   * logger.log('info', 'Operation completed successfully');
   * logger.log('warning', () => `High latency detected: ${latency}ms`);
   * ```
   *
   * @param level The severity level for the log entry
   * @param message The entry content or function that returns the content
   * @param args Additional arguments to include in the log entry
   */
  readonly log: (level: LogLevel, message: LogMessage, ...args: unknown[]) => void;
 
  /**
   * Flushes any buffered log entries, ensuring they are written to their destination.
   *
   * This method is optional and may not be available on all logger implementations. It is primarily used by loggers
   * that buffer entries for performance reasons (such as batch loggers or file loggers) to force immediate writing of
   * pending entries.
   *
   * The method can be either synchronous or asynchronous depending on the underlying implementation:
   *
   * - **Synchronous**: Returns `void` when the flush operation completes immediately
   * - **Asynchronous**: Returns a `Promise<void>` that resolves when the flush operation completes
   *
   * @example Handling both sync and async flush
   *
   * ```ts
   * const logger = createSomeLogger();
   * logger.info('Important message');
   *
   * // This approach simple calls the flush without investigating
   * // if it's defined, async or sync
   * await logger?.flush();
   * ```
   *
   * @example Synchronous flush
   *
   * ```ts
   * import { createConsoleLogLogger } from 'emitnlog/logger';
   *
   * const logger = createConsoleLogLogger();
   * logger.info('Buffered message');
   *
   * if (logger.flush) {
   *   logger.flush(); // Synchronous flush
   * }
   * ```
   *
   * @example Asynchronous flush
   *
   * ```ts
   * import { createFileLogger } from 'emitnlog/logger/node';
   *
   * const logger = createFileLogger('app.log');
   * logger.info('Buffered message');
   *
   * if (logger.flush) {
   *   await logger.flush(); // Asynchronous flush
   * }
   * ```
   *
   * @returns Either void for synchronous flush or Promise<void> for asynchronous flush, or undefined if not supported
   */
  readonly flush?: () => void | Promise<void>;
 
  /**
   * Closes the logger and releases any associated resources.
   *
   * This method is optional and may not be available on all logger implementations. It should be called when the logger
   * is no longer needed to ensure proper cleanup of resources such as file handles, network connections, or other
   * system resources.
   *
   * The method can be either synchronous or asynchronous depending on the underlying implementation:
   *
   * - **Synchronous**: Returns `void` when the close operation completes immediately
   * - **Asynchronous**: Returns a `Promise<void>` that resolves when the close operation completes
   *
   * After calling `close()`, the logger should not be used for further logging operations. Calling `flush()` before
   * `close()` is recommended to ensure all pending log entries are written before cleanup.
   *
   * @example Handling both sync and async close
   *
   * ```ts
   * const logger = createSomeLogger();
   * logger.info('Important message');
   *
   * // This approach simple calls the flush without investigating
   * // if it's defined, async or close
   * await logger?.close();
   * ```
   *
   * @example Synchronous close
   *
   * ```ts
   * import { createConsoleLogLogger } from 'emitnlog/logger';
   *
   * const logger = createConsoleLogLogger();
   * logger.info('Final message');
   *
   * if (logger.close) {
   *   logger.close(); // Synchronous close
   * }
   * ```
   *
   * @example Asynchronous close with file logger
   *
   * ```ts
   * import { createFileLogger } from 'emitnlog/logger/node';
   *
   * const logger = createFileLogger('app.log');
   * logger.info('Final message');
   *
   * if (logger.close) {
   *   await logger.close(); // Asynchronous close
   * }
   * ```
   *
   * @example A shutdown sequence that precisely investigates if the methods are sync or async.
   *
   * ```ts
   * const logger = createSomeLogger();
   * logger.info('Application shutting down');
   *
   * // Flush pending entries before closing
   * if (logger.flush) {
   *   const flushResult = logger.flush();
   *   if (flushResult instanceof Promise) {
   *     await flushResult;
   *   }
   * }
   *
   * // Close and release resources
   * if (logger.close) {
   *   const closeResult = logger.close();
   *   if (closeResult instanceof Promise) {
   *     await closeResult;
   *   }
   * }
   * ```
   *
   * @returns Either void for synchronous close or Promise<void> for asynchronous close, or undefined if not supported
   */
  readonly close?: () => void | Promise<void>;
}