mltk.utils.logger¶
Data logging utilities
See the source code on Github: mltk/utils/logger.py
Functions
|
Add a console logger to the given logger |
|
Return the logging level as a string |
|
Get or create a logger, optionally adding a console and/or file handler |
|
Make the given logger 'file-like' |
|
Redirect std logs to the given logger |
|
Set the logger's console level and return the previous level |
|
Print the run-time of the decorated function to the logger |
- get_logger(name='mltk', level='INFO', console=False, log_file=None, log_file_mode='w', parent=None, base_level='DEBUG', file_level='DEBUG')[source]¶
Get or create a logger, optionally adding a console and/or file handler
- Parameters:
parent (Logger) –
- add_console_logger(logger, level='INFO')[source]¶
Add a console logger to the given logger
- Parameters:
logger (Logger) –
- make_filelike(logger, level=20)[source]¶
Make the given logger ‘file-like’
- Parameters:
logger (Logger) –
- redirect_stream(logger, stream='stderr', close_atexit=True)[source]¶
Redirect std logs to the given logger
NOTE: This redirects ALL logs from the stream
- Return type:
Callable
- Parameters:
logger (Logger) –
stream (Union[TextIO, str]) –
- timing_decorator(f, level='INFO')[source]¶
Print the run-time of the decorated function to the logger
If a logger is found in the args then that is used, else if a logger is found in the ‘self’ argument, then that is used
- set_console_level(logger, level)[source]¶
Set the logger’s console level and return the previous level
- Return type:
str
- Parameters:
logger (Logger) –
level (str) –
- get_level(level)[source]¶
Return the logging level as a string
- Return type:
str
- Parameters:
level (Union[str, int]) –
- class ConsoleLoggerLevelContext[source]¶
-
- __dict__ = mappingproxy({'__module__': 'mltk.utils.logger', '__init__': <function ConsoleLoggerLevelContext.__init__>, '__enter__': <function ConsoleLoggerLevelContext.__enter__>, '__exit__': <function ConsoleLoggerLevelContext.__exit__>, '__dict__': <attribute '__dict__' of 'ConsoleLoggerLevelContext' objects>, '__weakref__': <attribute '__weakref__' of 'ConsoleLoggerLevelContext' objects>, '__doc__': None, '__annotations__': {}})¶
- __module__ = 'mltk.utils.logger'¶
- __weakref__¶
list of weak references to the object
- class DummyLogger[source]¶
-
- __dict__ = mappingproxy({'__module__': 'mltk.utils.logger', '__init__': <function DummyLogger.__init__>, 'debug': <function DummyLogger.debug>, 'info': <function DummyLogger.info>, 'warning': <function DummyLogger.warning>, 'error': <function DummyLogger.error>, 'exception': <function DummyLogger.exception>, 'write': <function DummyLogger.write>, 'flush': <function DummyLogger.flush>, '__dict__': <attribute '__dict__' of 'DummyLogger' objects>, '__weakref__': <attribute '__weakref__' of 'DummyLogger' objects>, '__doc__': None, '__annotations__': {}})¶
- __module__ = 'mltk.utils.logger'¶
- __weakref__¶
list of weak references to the object