mylogging.misc.misc_module module¶
Module with functions for misc subpackage.
- class mylogging.misc.misc_module.RedirectedLogsAndWarnings(logs: list[logging.LogRecord], warnings: list[dict[str, Any]], showwarning_backup: Callable, output_backup: Union[str, Path, None], stream_backup: Any)[source]¶
Bases:
object
Helper so resetting the original behavior is simple.
- close_redirect()[source]¶
Stop saving logs and warnings to lists. Restoring original logs and warnings if necessary.
- logs: list[logging.LogRecord]¶
- output_backup: Union[str, Path, None]¶
- showwarning_backup: Callable¶
- stream_backup: Any¶
- warnings: list[dict[str, Any]]¶
- mylogging.misc.misc_module.log_and_warn_from_lists(logs_list: None | list = None, warnings_list: None | list = None) None [source]¶
When logs and warnings was redirected to python lists. This can log it from the lists to file or console. Can be useful for example if using multiprocessing.
- Parameters
logs_list (None | list, optional) – [description]. Defaults to None.
warnings_list (None | list, optional) – [description]. Defaults to None.
- Raises
RuntimeError – [description]
- mylogging.misc.misc_module.redirect_logs_and_warnings(used_logs: list[logging.LogRecord], used_warnings: list, keep_logs_and_warnings: bool = True) RedirectedLogsAndWarnings [source]¶
For example if using many processes with multiprocessing, it may be beneficial to log from one place. It’s possible to log to variables (logs as well as warnings), pass it to the main process and then log it with workings filter etc.
To log stored logs and warnings, use
- Parameters
used_logs (list) – List where logs will be stored
used_warnings (list) – List where warnings will be stored
keep_logs_and_warnings (bool, optional) – If False, warnings and logs will be silenced. Default to True.
- Returns
Object, where you can reset redirect. Logs and warnings you already have from inserted parameters.
- Return type