My attempts at logging have not been very successful.
I have the following code which concludes with an intentional attempt to print a divide-by-zero result to test the logger:
import os, logging, logging.handlers
handler = logging.handlers.WatchedFileHandler(
os.environ.get("LOGFILE", "E:/Faults.log"))
formatter = logging.Formatter(logging.BASIC_FORMAT)
handler.setFormatter(formatter)
root = logging.getLogger()
root.setLevel(os.environ.get("LOGLEVEL", "DEBUG"))
root.addHandler(handler)
logging.debug("Logger check")
print(1/0)
Running this gives the following Console result:
Error:
Traceback (most recent call last):
File "E:\FaultLogger.py", line 12, in <module>
print(1/0)
ZeroDivisionError: division by zero
But the Fault.log file only records :
Output:
DEBUG:root:Logger check
but the debug does not recognise print(1/0) as a ZeroDivisionError.
It seems simple, but something is clearly wrong.
Any suggestions welcome!
Thanks
ASTRIKOR
buran write Aug-10-2021, 09:18 AM:Please, use proper tags when post code, traceback, output, etc.
See
BBcode help for more info.