apikeyper.log_engine package
Submodules
apikeyper.log_engine.helpers module
- class apikeyper.log_engine.helpers.CustomFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]
Bases:
FormatterCustomFormatter extends the logging.Formatter class to provide a custom formatting behavior. Specifically, it replaces ‘<ipython-input-…>’ patterns in record.pathname with ‘iPython’.
- format(record)[source]
Replaces <ipython-input-…> pattern in record.pathname with ‘iPython’.
- Parameters:
record (logging.LogRecord) – The record to format.
- Returns:
The formatted record.
- Return type:
- apikeyper.log_engine.helpers.clean_module_name(module_name)[source]
Replaces <ipython-input-…> pattern in the given module name with ‘iPython’.
- apikeyper.log_engine.helpers.is_number(string, force_integer=False, rounding=None)[source]
Checks if a given string can be converted to a number and optionally rounds or converts the result to an integer.
- Parameters:
- Returns:
The converted number, or the original string if it cannot be converted.
- Return type:
Module contents
log_engine
Author: Taylor-Jayde Date: Today’s Date
This module provides logging utilities tailored for the APIKeyPER application. It establishes a flexible logging mechanism with support for both console and file outputs, featuring rich, colored console logs using the Rich library. The module also incorporates a Singleton design pattern for the Logger class, ensuring consistent logging behavior across the application.
Furthermore, the module provides a meta-class ‘Loggable’ which can be inherited by other classes to instantly equip them with logging capabilities.
- Key components:
Logger: A Singleton class responsible for managing application logging.
Loggable: A meta-class providing logging capabilities to the classes that inherit from it.
- Dependencies:
logging: Standard library module for event logging.
RichHandler from rich.logging: Provides rich, colored output for console logs.
inspect: Standard library module for introspecting live objects.
apikeyper.__about__: Module providing metadata about the APIKeyPER application.
apikeyper.log_engine.helpers: Helper functions for the logging engine.
- class apikeyper.log_engine.Loggable(parent_log_device=None, **kwargs)[source]
Bases:
objectA metaclass to enhance classes with logging capabilities. Classes that inherit from ‘Loggable’ can instantly access a logger without manually setting it up. This logger is derived from a parent logger, ensuring consistent logging behavior and hierarchy.
- - log_device
The logger device associated with the instance of the class.
- __is_member__()[source]
Checks whether the caller of this method is a member of the same class.
- Raises:
PermissionError – If the caller of this method is not a member of the same class.
- create_child_logger(name=None, override=False)[source]
Creates and returns a child logger of this object’s logger.
- Parameters:
- Returns:
An instance of the Logger class that represents the child logger.
- Return type:
- property log_device
- class apikeyper.log_engine.Logger(name, *args, **kwargs)[source]
Bases:
objectA Singleton class responsible for managing the logging mechanisms of the application. It ensures consistent logging behavior across different parts of the application by maintaining single instances of loggers with specific names. The class supports logging to both the console (with colored output) and a file.
- - instances
Keeps track of logger instances to implement the Singleton pattern.
- Type:
- static __new__(cls, name, *args, **kwargs)[source]
Creates a new instance or returns an existing instance of the Logger class for the provided name. This method ensures that only one instance of Logger with a given name exists, implementing the Singleton pattern.
- get_child_names()[source]
Fetches the names of all child loggers associated with this logger instance.
- instances = {'APIKeyPER': <apikeyper.log_engine.Logger object>, 'APIKeyPER.<module>': <apikeyper.log_engine.Logger object>, 'APIKeyPER.log_engine': <apikeyper.log_engine.Logger object>, 'APIKeyPER.ui': <apikeyper.log_engine.Logger object>}
- set_level(console_level=None, file_level=None)[source]
Updates the logging levels for both the console and file handlers. If provided, also updates child loggers.
- Parameters:
console_level (logging level object, optional) – The console logging level. Defaults to None.
file_level (logging level object, optional) – The file logging level. Defaults to None.
- apikeyper.log_engine.add_child(name=None, console_level=None, file_level=None)