API Reference
reconplogger module
Classes:
|
Class designed to be inherited by other classes to add an rlogger property. |
Functions:
|
Adds a file handler to a given logger. |
|
Sets up logging configuration, configures flask to use it, and returns the logger. |
Returns the current correlation id. |
|
|
Returns an already existing logger. |
|
Loads a logging configuration from path or environment variable or dictionary object. |
|
Sets up logging configuration and returns the logger. |
|
Replaces the handlers of a given logger. |
|
Sets the correlation id for the current application context. |
|
Logs one message to each debug, info and warning levels intended for testing. |
- class reconplogger.RLoggerProperty(*args, **kwargs)[source]
Bases:
object
Class designed to be inherited by other classes to add an rlogger property.
Attributes:
The logger property for the 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.add_file_handler(logger, file_path, format='%(asctime)s\\t%(levelname)s -- %(filename)s:%(lineno)s -- %(message)s', level='DEBUG')[source]
Adds a file handler to a given logger.
- Parameters
- Return type
- Returns
The handler object which could be used for removeHandler.
- reconplogger.flask_app_logger_setup(flask_app, logger_name='plain_logger', config=None, level=None, env_prefix='LOGGER', parent=None)[source]
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.env_prefix (
str
) – Environment variable names prefix for overriding logger configuration.parent (
Optional
[Logger
]) – Set for logging delegation to the parent.
- Return type
- Returns
The logger object.
- reconplogger.get_correlation_id()[source]
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.get_logger(logger_name)[source]
Returns an already existing logger.
- Parameters
logger_name (
str
) – Name of the logger to get.- Return type
- Returns
The logger object.
- Raises
ValueError – If the logger does not exist.
- reconplogger.load_config(cfg=None, reload=False)[source]
Loads a logging configuration from path or environment variable or dictionary object.
- reconplogger.logger_setup(logger_name='plain_logger', config=None, level=None, env_prefix='LOGGER', reload=False, parent=None, init_messages=False)[source]
Sets up logging configuration and returns the logger.
- Parameters
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.env_prefix (
str
) – Environment variable names prefix for overriding logger configuration.reload (
bool
) – Whether to reload logging configuration overriding any previous settings.parent (
Optional
[Logger
]) – Set for logging delegation to the parent.init_messages (
bool
) – Whether to log init and test messages.
- Return type
- Returns
The logger object.
- reconplogger.replace_logger_handlers(logger, handlers)[source]
Replaces the handlers of a given logger.
- reconplogger.set_correlation_id(correlation_id)[source]
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.