API Reference
reconplogger module
Classes:
|
Class designed to be inherited by other classes to add an rlogger property. |
Functions:
Installs a named handler on the root logger and removes stream handlers from named loggers. |
|
|
Sets up logging configuration and returns the logger. |
|
Sets up logging configuration, configures flask to use it, and returns the logger. |
Returns the current correlation id. |
|
|
Sets the correlation id for the current application context. |
|
Context manager to set the correlation id for the current application context. |
|
Adds a file handler to a given logger. |
- class reconplogger.RLoggerProperty(*args, **kwargs)
Bases:
objectClass designed to be inherited by other classes to add an rlogger property.
Methods:
__init__(*args, **kwargs)Initializer for LoggerProperty class.
Attributes:
The logger property for the class.
- __init__(*args, **kwargs)
Initializer for LoggerProperty class.
- property rlogger
The logger property for the class.
- Getter:
Returns the current logger.
- Setter:
Sets the reconplogger logger if True or sets null_logger if False or sets the given logger.
- Raises:
ValueError – If an invalid logger value is given.
- reconplogger.configure_root_logger()
Installs a named handler on the root logger and removes stream handlers from named loggers.
After this call every log record in the process flows through the single root handler, regardless of which named logger emitted it. All named loggers (except those with only
NullHandlerinstances) have theirStreamHandlerinstances removed andpropagateset toTrueso records bubble up to the root while keeping non-stream handlers such as file handlers attached.- Return type:
- reconplogger.logger_setup(logger_name='plain_logger', config=None, level=None)
Sets up logging configuration and returns the logger.
If the environment variable
LOGGER_ROOT_HANDLERis set to the name of a handler defined in the logging config, that handler is installed on the root logger so that all third-party loggers (which propagate to the root by default) are also captured. The primary logger level remains controlled bylevel/LOGGER_LEVEL, while the root logger level can be controlled independently throughLOGGER_ROOT_LEVEL. On subsequent calls the same primary logger is returned without reconfiguring the root. To force a fresh configuration pass, callreset_configs()first.- Parameters:
- Return type:
- Returns:
The logger object.
- reconplogger.flask_app_logger_setup(flask_app, logger_name='plain_logger', config=None, level=None)
Sets up logging configuration, configures flask to use it, and returns the logger.
- Parameters:
flask_app (flask.app.Flask) – The flask app object.
logger_name (
str) – Name of the logger that needs to be used.config (
Optional[str]) – Configuration string or path to configuration file or configuration file via environment variable.level (
Optional[str]) – Optional logging level that overrides one in config.
- Return type:
- Returns:
The logger object.
- reconplogger.get_correlation_id()
Returns the current correlation id.
- Raises:
ImportError – When flask package not available.
RuntimeError – When run outside an application context or if flask app has not been setup.
- Return type:
- reconplogger.set_correlation_id(correlation_id)
Sets the correlation id for the current application context.
- Raises:
ImportError – When flask package not available.
RuntimeError – When run outside an application context or if flask app has not been setup.
- reconplogger.correlation_id_context(correlation_id)
Context manager to set the correlation id for the current application context.
Use as with correlation_id_context(correlation_id): …. Calls to get_correlation_id() will return the correlation id set for the context.
- reconplogger.add_file_handler(logger, file_path, format='%(asctime)s\\t%(levelname)s -- %(filename)s:%(lineno)s -- %(message)s', level='DEBUG')
Adds a file handler to a given logger.
- Parameters:
- Return type:
- Returns:
The handler object which could be used for removeHandler.