Utils
The utils module is where helper functions are located, for example configureLogging and getQueuedLogger.
- configureLogging(config)
Configures Python’s logging framework based on the provided configuration.
- Parameters:
config (appsettings2.Configuration) – (OPTIONAL) An
appsettings2.Configurationto use for logging configuration. Default isNone.- Returns:
As a convenience, the list of logging Handlers which were configured, in case the calling application needs them for any reason.
Example:
import hanaro
hanaro.configureLogging()
class Foo:
def __init__(self) -> None:
self.__logger = logging.getLogger('ur.special')
self.__logger.info('Hello, World!')
# Outputs to console (depends on format spec):
# [2025-12-31 12:59:59] level=INFO name=ur.special Hello, World!
- getLogger(name, level)
Similar to Python’s own
logging.getLogger(...)except this function will attempt to resolve the name of the calling module whennameis not provided.- Parameters:
name (str) – (OPTIONAL) The name for the logger instance. When not provided an attempt will be made to resolve the name of the calling module. Default is
None.level (int|str) – (OPTIONAL) The default logging Level for the Logger. Default is
`NOTSET`.
- Returns:
A
logging.Loggerinstance that only has aQueuedHandlerconfigured.
Example:
import hanaro
class Foo:
def __init__(self) -> None:
self.__logger = hanaro.getLogger()
self.__logger.info('Hello, World!')
# Outputs to console (depends on format spec):
# [2025-12-31 12:59:59] level=INFO name=my.module Hello, World!
- getQueuedLogger(name, level)
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 (str) – (OPTIONAL) The name for the logger instance. When not provided an attempt will be made to resolve the name of the calling module. Default is
None.level (int|str) – (OPTIONAL) The default logging Level for the Logger. Default is
`NOTSET`.
- Returns:
A
logging.Loggerinstance that only has aQueuedHandlerconfigured.
Example:
import hanaro
class Foo:
def __init__(self) -> None:
self.__logger = hanaro.getQueuedLogger(__name__)
self.__logger.info('Hello, World!')
# Outputs to console:
# (Nothing, because the logging record went into a queue.)
# SEE ALSO: ``handleQueuedLogRecords()``
- handleQueuedLogRecords()
Outputs all queued log records using the root logger.
Example:
import hanaro
hanaro.configureLogging({
'logging': {
'level': 'DEBUG',
'handlers': [{'type':'console','level':'DEBUG'}]
}
})
class Foo:
def __init__(self) -> None:
self.__logger = logging.getQueuedLogger('ur.special')
self.__logger.info('Hello, World!')
hanaro.handleQueuedLogRecords()
# Outputs to console (depends on format spec):
# [2025-12-31 12:59:59] level="INFO" source="ur.special" msg="Hello, World!"