reporterror - Portable error reporting module
- Purpose:
This module is designed to report program errors to the console and/or a log file, using the
Log
class.- Platform:
Linux/Windows | Python 3.6+
- Developer:
J Berendt
- Email:
- Comments:
n/a
- Example:
For a usage example, refer to the
reporterror()
method’s docstring.
- reporterror.reporterror(error: Exception, logevent=False, logfilepath='/tmp/reporterror.log')[source]
Report an error, derived from the passed
Exception
object.- Parameters:
error (Exception) – Python
Exception
object from the built-in try/except error handler. Refer to the use example below.logevent (bool, optional) – Send the error to a log file. Defaults to False.
logfilename (str, optional) –
Full path to the log file. Defaults to:
Linux:
'/tmp/reporterror.log'
Windows:
'c:/temp/reporterror.log'
Other:
None
Note
The
logevent
parameter assumes the log file exists and the header is already written.For general logging help, you can use the
Log
class which is built intoutils4
.- Example:
Report a simple error to the terminal:
>>> from utils4.reporterror import reporterror >>> try: >>> 1/0 # Force a known error. >>> except Exception as err: >>> reporterror(err)
Output:
ERROR: division by zero TYPE: <class 'ZeroDivisionError'> MODU: <./module/with/error.py> FUNC: <func_name> LINE: 2 CMD: 1/0
Report a simple error to the terminal and create a log file entry:
>>> from utils4.reporterror import reporterror >>> try: >>> 1/0 # Force a known error. >>> except Exception as err: >>> reporterror(err, logevent=True, logfilepath='/tmp/errors.log')
Tip
Reminder: The log file must already exist.
For help with the
utils4.log
module, please refer to the documentation here:Log
.