syntropylog
Version:
An instance manager with observability for Node.js applications
100 lines (99 loc) • 4.63 kB
TypeScript
import { Transport } from './transports/Transport';
import type { LoggerOptions, LogBindings, LogMetadata, LogRetentionRules, LogFormatArg, JsonValue } from '../types';
import type { LogLevel } from './levels';
import { IContextManager } from '../context';
import { SerializerRegistry } from '../serialization/SerializerRegistry';
import { MaskingEngine } from '../masking/MaskingEngine';
import { SyntropyLog } from '../SyntropyLog';
import { ILogger } from './ILogger';
export interface LoggerDependencies {
contextManager: IContextManager;
serializerRegistry: SerializerRegistry;
maskingEngine: MaskingEngine;
syntropyLogInstance: SyntropyLog;
}
/**
* @class Logger
* @description The core logger implementation. It orchestrates the entire logging
* pipeline, from argument parsing and level checking to serialization, masking,
* and dispatching to transports.
*/
export declare class Logger {
level: LogLevel;
name: string;
private transports;
private bindings;
private dependencies;
constructor(name: string, transports: Transport[], dependencies: LoggerDependencies, options?: Omit<LoggerOptions, 'transports'>);
/**
* @private
* The core asynchronous logging method that runs the full processing pipeline.
* It handles argument parsing, level filtering, serialization, masking,
* and finally dispatches the processed log entry to the appropriate transports.
* @param {LogLevel} level - The severity level of the log message.
* @param {...(LogFormatArg | LogMetadata | JsonValue)[]} args - The arguments to be logged, following the Pino-like signature (e.g., `(obj, msg, ...)` or `(msg, ...)`).
* @returns {Promise<void>}
*/
private _log;
/**
* Logs a message at the 'info' level.
* @param {...(LogFormatArg | LogMetadata | JsonValue)[]} args - The arguments to log.
*/
info(...args: (LogFormatArg | LogMetadata | JsonValue)[]): Promise<void>;
/**
* Logs a message at the 'warn' level.
* @param {...(LogFormatArg | LogMetadata | JsonValue)[]} args - The arguments to log.
*/
warn(...args: (LogFormatArg | LogMetadata | JsonValue)[]): Promise<void>;
/**
* Logs a message at the 'error' level.
* @param {...(LogFormatArg | LogMetadata | JsonValue)[]} args - The arguments to log.
*/
error(...args: (LogFormatArg | LogMetadata | JsonValue)[]): Promise<void>;
/**
* Logs a message at the 'debug' level.
* @param {...(LogFormatArg | LogMetadata | JsonValue)[]} args - The arguments to log.
*/
debug(...args: (LogFormatArg | LogMetadata | JsonValue)[]): Promise<void>;
/**
* Logs a message at the 'trace' level.
* @param {...(LogFormatArg | LogMetadata | JsonValue)[]} args - The arguments to log.
*/
trace(...args: (LogFormatArg | LogMetadata | JsonValue)[]): Promise<void>;
/**
* Logs a message at the 'fatal' level.
* @param {...(LogFormatArg | LogMetadata | JsonValue)[]} args - The arguments to log.
*/
fatal(...args: (LogFormatArg | LogMetadata | JsonValue)[]): Promise<void>;
/**
* Dynamically updates the minimum log level for this logger instance.
* Any messages with a severity lower than the new level will be ignored.
* @param {LogLevel} level - The new minimum log level.
*/
setLevel(level: LogLevel): void;
/**
* Creates a new child logger instance that inherits the parent's configuration
* and adds the specified bindings.
* @param {LogBindings} bindings - Key-value pairs to bind to the child logger.
* @returns {ILogger} A new logger instance with the specified bindings.
*/
child(bindings: LogBindings): ILogger;
/**
* Creates a new logger instance with a `source` field bound to it.
* @param {string} source - The name of the source (e.g., 'redis', 'AuthModule').
* @returns {ILogger} A new logger instance with the `source` binding.
*/
withSource(source: string): ILogger;
/**
* Creates a new logger instance with a `retention` field bound to it.
* @param {LogRetentionRules} rules - A JSON object containing the retention rules.
* @returns {ILogger} A new logger instance with the `retention` binding.
*/
withRetention(rules: LogRetentionRules): ILogger;
/**
* Creates a new logger instance with a `transactionId` field bound to it.
* @param {string} transactionId - The unique ID of the transaction.
* @returns {ILogger} A new logger instance with the `transactionId` binding.
*/
withTransactionId(transactionId: string): ILogger;
}