LoggerFactory

class logman.logger_factory.LoggerFactory[source]

Bases: object

A factory class for creating and managing loggers with file rotation and console output.

_filePath

The default log file path.

Type:

Union[str, os.PathLike]

_maxBytes

The maximum size of the log file before rotation occurs.

Type:

int

_loggers

A dictionary to store created loggers.

Type:

Dict[str, logging.Logger]

_lock

A lock to ensure thread safety.

Type:

threading.Lock

_initialized

A flag to check if logging has been initialized.

Type:

bool

_handlers

A list to store added handlers.

Type:

List[logging.Handler]

classmethod addHandler(handler: Handler) None[source]

Add a handler to the root logger.

Parameters:

handler (logging.Handler) – The handler to add.

Returns:

None

classmethod getLogger(name: str) Logger[source]

Get a logger by name.

This method initializes the logging configuration if necessary and returns a logger with the specified name.

Parameters:

name (str) – The name of the logger to retrieve.

Returns:

The logger instance with the specified name.

Return type:

logging.Logger

classmethod listHandlers() List[Handler][source]

List all handlers attached to the root logger.

Returns:

A list of handlers attached to the root logger.

Return type:

List[logging.Handler]

classmethod removeHandler(handler: Handler) None[source]

Remove a handler from the root logger.

Parameters:

handler (logging.Handler) – The handler to remove.

Returns:

None

classmethod setFormatter(formatter: Formatter) None[source]

Set the formatter for all handlers on the root logger.

Parameters:

formatter (logging.Formatter) – The formatter to set.

Returns:

None