LoggerFactory
Upgather SDK / LoggerFactory
Class: LoggerFactory
Defined in: lib/utils/logger/LoggerFactory.ts:46
Factory for creating logger instances based on configuration. Centralizes logger instantiation logic following the Factory pattern.
Remarks
This factory simplifies logger creation by handling the logic of choosing between custom loggers, default loggers, and silent loggers based on configuration.
The factory follows these rules:
- If a custom logger is provided, use it
- If log level is 'silent', create a SilentLogger
- Otherwise, create a DefaultLogger with the given configuration
Examples
Creating a default logger:
import { LoggerFactory } from '@upgather/upgather-sdk';
const logger = LoggerFactory.createLogger(undefined, {
level: 'debug',
prefix: 'my-app'
});
Using a custom logger:
import winston from 'winston';
import { LoggerFactory, LoggerInterface } from '@upgather/upgather-sdk';
const winstonLogger = winston.createLogger({ level: 'info' });
const customLogger: LoggerInterface = {
debug: (msg, ...meta) => winstonLogger.debug(msg, ...meta),
info: (msg, ...meta) => winstonLogger.info(msg, ...meta),
warn: (msg, ...meta) => winstonLogger.warn(msg, ...meta),
error: (msg, ...meta) => winstonLogger.error(msg, ...meta),
};
const logger = LoggerFactory.createLogger(customLogger);
Constructors
new LoggerFactory()
new LoggerFactory():
LoggerFactory
Returns
Methods
createLogger()
staticcreateLogger(customLogger?,config?):LoggerInterface
Defined in: lib/utils/logger/LoggerFactory.ts:59
Creates a logger instance from configuration. If a custom logger is provided, returns it; otherwise creates a default logger.
Parameters
customLogger?
Optional custom logger implementation
config?
Optional configuration for the default logger
Returns
A logger instance implementing LoggerInterface
Remarks
The factory prioritizes custom loggers over configuration. If both are provided, the custom logger is returned and the configuration is ignored.