gwkokab.utils.exceptions¶
Custom Logged Exceptions and Warnings for gwkokab.
This module provides a registry of standard Python exceptions and warnings extended with automatic logging capabilities via loguru.
The mixin classes LoggedMixinException and LoggedMixinWarning provide
the functionality to format and log messages for exceptions and warnings, respectively.
The custom exception and warning classes inherit from these mixins and the corresponding
built-in exception or warning classes. When an instance of these custom classes is
created, the message is formatted using the provided arguments and keyword arguments,
and then logged at the appropriate level (error for exceptions and warning for
warnings). If formatting fails, the original message is used without formatting. This
allows for consistent logging of error and warning messages throughout the application.
You can use these custom exceptions and warnings in your code to automatically log messages when they are raised or issued. For example:
import warnings
from gwkokab.utils.exceptions import LoggedMixinException, LoggedMixinWarning
class LoggedValueError(LoggedMixinException, ValueError):
pass
class LoggedUserWarning(LoggedMixinWarning, UserWarning):
pass
warnings.warn("This is a warning message", LoggedUserWarning)
raise LoggedValueError("Invalid value: {value}", value=42)
Exceptions¶
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Classes¶
A mixin class for exceptions that logs the error message using loguru when the |
|
A mixin class for warnings that logs the warning message using loguru when the |
Module Contents¶
- exception gwkokab.utils.exceptions.LoggedAssertionError(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶
Bases:
LoggedMixinException,AssertionErrorAssertionErrorthat logs its message atERRORlevel when raised.Initialize self. See help(type(self)) for accurate signature.
- exception gwkokab.utils.exceptions.LoggedAttributeError(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶
Bases:
LoggedMixinException,AttributeErrorAttributeErrorthat logs its message atERRORlevel when raised.Initialize self. See help(type(self)) for accurate signature.
- exception gwkokab.utils.exceptions.LoggedDeprecationWarning(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶
Bases:
LoggedMixinWarning,DeprecationWarningDeprecationWarningthat logs its message atWARNINGlevel when issued.Initialize self. See help(type(self)) for accurate signature.
- exception gwkokab.utils.exceptions.LoggedFileNotFoundError(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶
Bases:
LoggedMixinException,FileNotFoundErrorFileNotFoundErrorthat logs its message atERRORlevel when raised.Initialize self. See help(type(self)) for accurate signature.
- exception gwkokab.utils.exceptions.LoggedImportError(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶
Bases:
LoggedMixinException,ImportErrorImportErrorthat logs its message atERRORlevel when raised.Initialize self. See help(type(self)) for accurate signature.
- exception gwkokab.utils.exceptions.LoggedIndexError(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶
Bases:
LoggedMixinException,IndexErrorIndexErrorthat logs its message atERRORlevel when raised.Initialize self. See help(type(self)) for accurate signature.
- exception gwkokab.utils.exceptions.LoggedKeyError(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶
Bases:
LoggedMixinException,KeyErrorKeyErrorthat logs its message atERRORlevel when raised.Initialize self. See help(type(self)) for accurate signature.
- exception gwkokab.utils.exceptions.LoggedNotImplementedError(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶
Bases:
LoggedMixinException,NotImplementedErrorNotImplementedErrorthat logs its message atERRORlevel when raised.Initialize self. See help(type(self)) for accurate signature.
- exception gwkokab.utils.exceptions.LoggedRuntimeWarning(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶
Bases:
LoggedMixinWarning,RuntimeWarningRuntimeWarningthat logs its message atWARNINGlevel when issued.Initialize self. See help(type(self)) for accurate signature.
- exception gwkokab.utils.exceptions.LoggedTypeError(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶
Bases:
LoggedMixinException,TypeErrorTypeErrorthat logs its message atERRORlevel when raised.Initialize self. See help(type(self)) for accurate signature.
- exception gwkokab.utils.exceptions.LoggedUserWarning(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶
Bases:
LoggedMixinWarning,UserWarningUserWarningthat logs its message atWARNINGlevel when issued.Initialize self. See help(type(self)) for accurate signature.
- exception gwkokab.utils.exceptions.LoggedValueError(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶
Bases:
LoggedMixinException,ValueErrorValueErrorthat logs its message atERRORlevel when raised.Initialize self. See help(type(self)) for accurate signature.
- class gwkokab.utils.exceptions.LoggedMixinException(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶
A mixin class for exceptions that logs the error message using loguru when the exception is instantiated.
The message is formatted using the provided arguments and keyword arguments. If formatting fails, the original message is used without formatting. The formatted message is logged at the error level.
- Parameters:
msg (str) – Message template, using loguru’s
{}-style formatting.*args (Any) – Positional arguments substituted into
msg.loguru_opt (dict[str, Any], optional) – Options forwarded to
loguru.Logger.opt(). Defaults to{"depth": 1}so the log record points at the caller that raised the exception rather than at this mixin.**kwargs (Any) – Keyword arguments substituted into
msg.
- class gwkokab.utils.exceptions.LoggedMixinWarning(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶
A mixin class for warnings that logs the warning message using loguru when the warning is instantiated.
The message is formatted using the provided arguments and keyword arguments. If formatting fails, the original message is used without formatting. The formatted message is logged at the warning level.
- Parameters:
msg (str) – Message template, using loguru’s
{}-style formatting.*args (Any) – Positional arguments substituted into
msg.loguru_opt (dict[str, Any], optional) – Options forwarded to
loguru.Logger.opt(). Defaults to{"depth": 1}so the log record points at the caller that issued the warning rather than at this mixin.**kwargs (Any) – Keyword arguments substituted into
msg.