mylogging.str_formating module¶
Internal module for functions that will be imported in __init__.py for shorter syntax.
- class mylogging.str_formating.StringObject(message: str)[source]¶
Bases:
str
Custom wrapper so it can be edited.
- mylogging.str_formating.format_str(message: str, caption: str = 'User message', around: Union[bool, str] = 'config', use_object_conversion: bool = True, indent: int = 4, uncolored_message: None | str = None, level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] = 'WARNING') str [source]¶
Return enhanced colored message. Used for raising exceptions, assertions.
- Parameters
message (str) – Any string content of warning.
caption (str, optional) – Heading of warning. Defaults to ‘User message’.
around (Union[bool, str], optional) – If print to file - whether print ====== lines around. If ‘auto’, then if output is to file, then around = False, if output == “console”, around = True. If ‘config’, use global config (defaults ‘auto’). Defaults to ‘config’.
use_object_conversion (bool, optional) – Turn into object (If call in raise - only way to print colors). If you need string to variable, call str(). Defaults to True.
indent (int, optional) – By how many spaces are logs indented (for better visibility). If 0, than no indentation. Defaults to 4.
uncolored_message (None | str, optional) – Appendix added to end that will not be colorized (or already is colorized). Used for example for tracebacks. Defaults to None.
level (str, optional) – Defaults to “DEBUG”.
- Returns
Enhanced message as a string, that is wrapped by and can be colorized.
- Return type
str
Example
>>> format_str("Formated", caption="Caption") ========= Caption ========= Formated ===========================
- mylogging.str_formating.use_object_conversion_str(message: str) StringObject [source]¶
Make a class from a string to be able to apply escape characters and colors if raise.
- Parameters
message (str) – Any string you use.
- Returns
Object, that can return string if printed or used in warning or raise.
- Return type
Object
- mylogging.str_formating.wrap(message: str, caption: None | str = None, level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] = 'WARNING')[source]¶
Wrap string with significant lines (===========) with optional caption.
- Parameters
message (str) – Message to be wrapped.
caption (None | str, optional) – In the middle of first wrapping line. Defaults to None.
level (Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], optional) – Define what color will be used. Defaults to “WARNING”.
- Returns
Formatted message
- Return type
str
Example
>>> print(wrap("Hello", caption="Caption")) ========= Caption ========= Hello ===========================