syntropylog
Version:
An instance manager with observability for Node.js applications
67 lines (66 loc) • 3.38 kB
TypeScript
import { SyntropyLog } from '../SyntropyLog';
import { SyntropyLogConfig } from '../config';
import { ILogger } from './ILogger';
import { IContextManager } from '../context/IContextManager';
import { JsonValue } from '../types';
/**
* @class LoggerFactory
* @description Manages the lifecycle and configuration of all logging components.
* An instance of this factory is created by `syntropyLog.init()` and acts as the central
* orchestrator for creating and managing logger instances and their dependencies.
*/
export declare class LoggerFactory {
/** @private The manager for handling asynchronous contexts. */
private readonly contextManager;
/** @private The main framework instance, used as a mediator. */
private readonly syntropyLogInstance;
/** @private The array of transports to which logs will be dispatched. */
private readonly transports;
/** @private The global minimum log level for all created loggers. */
private readonly globalLogLevel;
/** @private The global service name, used as a default for loggers. */
private readonly serviceName;
/** @private The engine responsible for serializing complex objects. */
private readonly serializerRegistry;
/** @private The engine responsible for masking sensitive data. */
private readonly maskingEngine;
/** @private A pool to cache logger instances by name for performance. */
private readonly loggerPool;
/**
* @constructor
* @param {SyntropyLogConfig} config - The global configuration object.
* @param {IContextManager} contextManager - The shared context manager instance.
* @param {SyntropyLog} syntropyLogInstance - The main framework instance for mediation.
* @description Initializes all core logging engines and orchestrates transport setup.
* It follows a key principle for transport configuration:
* - **If `config.logger.transports` is provided:** The factory trusts the user's
* configuration completely and uses the provided transports as-is. It is the user's
* responsibility to configure them correctly (e.g., adding sanitization).
* - **If no transports are provided:** The factory creates a single, production-safe
* `ConsoleTransport` by default, which includes a built-in `SanitizationEngine`.
*/
constructor(config: SyntropyLogConfig, contextManager: IContextManager, syntropyLogInstance: SyntropyLog);
/**
* Retrieves a logger instance by name. If the logger does not exist, it is created
* and cached for subsequent calls.
* @param {string} [name='default'] - The name of the logger to retrieve.
* @param {Record<string, JsonValue>} [bindings] - Optional bindings to apply to the logger.
* @returns {ILogger} The logger instance.
*/
getLogger(name?: string, bindings?: Record<string, JsonValue>): ILogger;
/**
* Creates a stable cache key for logger instances.
* @private
*/
private createCacheKey;
/**
* Calls the `flush` method on all configured transports to ensure buffered
* logs are written before the application exits.
*/
flushAllTransports(): Promise<void>;
/**
* Shuts down the logger factory and all its transports.
* This ensures that all buffered logs are written and resources are cleaned up.
*/
shutdown(): Promise<void>;
}