Reference¶
ExceptionHandler
¶
Handler for logging and managing exceptions.
Info
This class logs exceptions to a specified file, with log rotation occurring at 10 MB. It can handle exceptions by logging the error message and additional data, and optionally raise critical exceptions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
log_file |
str
|
The file where logs should be written. |
required |
lvl |
ErrorLevelEnum
|
The default logging level. |
DEBUG
|
handle_exception(exception, return_log_as_str=False)
staticmethod
¶
Handles a given exception by logging it and optionally raising it.
Info
This method logs the exception message and any additional data. If the exception level is CRITICAL, the exception is raised. It can also return the log message as a string if specified.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exception |
CustomException
|
The exception to be handled. |
required |
return_log_as_str |
bool
|
Whether to return the log message as a string. |
False
|
Returns:
Type | Description |
---|---|
str | None
|
The log message if return_log_as_str is True, otherwise None. |
Raises:
Type | Description |
---|---|
CustomException
|
If level is CRITICAL. |