hanaro.utils#
Provides helper methods such as configure_logging, get_logger(...), etc.
- configure_logging(configuration=None, force=False)#
Configure logging according to the configuration provided.
- Parameters:
configuration (
Union[dict[str,Any],Configuration,None]) – The configuration object to pull logging settings from. Omit to apply defaults.force (
bool) – Should configuration be applied (forced) even if handlers have already been configured?
- Return type:
list[Handler]- Returns:
A list of handlers which are configured.
Usage#
hanaro.configure_logging() hanaro.configure_logging({'logging': {'handlers': [{'type': 'console'}]}})
- get_logger(name=None, level=0, allow_queued_logger=None)#
Similar to Python’s own
logging.getLogger(...)except this function attempts to resolve the name of the calling module when no name has been provided.- Parameters:
name (
Optional[str]) – The name for the logger instance. When not provided an attempt will be made to resolve the name of the calling module.level (
int|str) – The default logging Level for the Logger.
- Return type:
Logger- Returns:
A
logging.Loggerinstance.
Usage#
logger = hanaro.get_logger() logger = hanaro.get_logger('my_module', logging.DEBUG)
- get_queued_logger(name=None, level=0)#
Similar to Python’s own
logging.getLogger(...)except this function provides a bare-bones Logger that is only configured to forward logging Records to aQueuedHandler(intentionally bypassing the rest of the logging system).- Parameters:
name (
Optional[str]) – The name for the logger instance. When not provided an attempt will be made to resolve the name of the calling module.level (
int|str) – The default logging Level for the Logger.
- Return type:
Logger- Returns:
A
logging.Loggerinstance that only has aQueuedHandlerconfigured.
Usage#
logger = hanaro.get_queued_logger() logger = hanaro.get_queued_logger('async_worker', logging.DEBUG)
- handle_queued_log_records()#
Output all queued log records using the root logger.
This is a QOL function for devs using :py:func:
get_queued_logger.This function can be called on any thread, but it is designed to be called from a single thread, ideally the main thread.
- Return type:
None
Usage#
while not exitProgram: doProgramLogic() hanaro.handle_queued_log_records() # (consider signal or sleep to play nice with CPU)