API Reference¶
reconplogger module¶
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. |
-
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.
-
reconplogger.
flask_app_logger_setup
(flask_app, logger_name='plain_logger', config=None, level=None, env_prefix='LOGGER')[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 (str) – Configuration string or path to configuration file or configuration file via environment variable.
level (str) – Optional logging level that overrides one in config.
env_prefix (str) – Environment variable names prefix for overriding logger configuration.
- Returns
The logger object.
- Return type
-
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.
-
reconplogger.
get_logger
(logger_name)[source]¶ Returns an already existing logger.
- Parameters
logger_name (str) – Name of the logger to get.
- Returns
The logger object.
- Return type
- Raises
ValueError – If the logger does not exist.
-
reconplogger.
load_config
(cfg=None)[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', 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 (str or None) – Configuration string or path to configuration file or configuration file via environment variable.
level (str or int or None) – Optional logging level that overrides one in config.
env_prefix (str) – Environment variable names prefix for overriding logger configuration.
init_messages (bool) – Whether to log init and test messages.
- Returns
The logger object.
- Return type
-
reconplogger.
replace_logger_handlers
(logger, handlers='plain_logger')[source]¶ Replaces the handlers of a given logger.
- Parameters
logger (logging.Logger or str) – Object or name of logger to replace handlers.
handlers (list[logging.StreamHandler] or logging.Logger or str) – List of handlers or object or name of logger from which to get handlers.
-
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.