Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Windows compatibility
#13
It looks there is some misunderstanding how logging works.
print(1/0) produce unhandled error and program ends with the traceback you show.

You need to handle the error with try/except/else/finally block (note, not all 4 are mandatory) and only if you want you can log something, e.g.

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")
try:
    print(1/0)
except ZeroDivisionError:
    logging.critical('Division by zero')
ndc85430 likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
Windows compatibility - by Astrikor - Aug-03-2021, 08:52 AM
RE: Windows compatibility - by Larz60+ - Aug-03-2021, 09:49 AM
RE: Windows compatibility - by Astrikor - Aug-03-2021, 10:12 AM
RE: Windows compatibility - by DeaD_EyE - Aug-03-2021, 10:27 AM
RE: Windows compatibility - by supuflounder - Aug-03-2021, 10:38 AM
RE: Windows compatibility - by Astrikor - Aug-03-2021, 11:39 AM
RE: Windows compatibility - by Astrikor - Aug-04-2021, 08:31 AM
RE: Windows compatibility - by jefsummers - Aug-04-2021, 11:14 AM
RE: Windows compatibility - by Astrikor - Aug-04-2021, 12:18 PM
RE: Windows compatibility - by ndc85430 - Aug-04-2021, 12:40 PM
RE: Windows compatibility - by Astrikor - Aug-04-2021, 03:02 PM
RE: Windows compatibility - by Astrikor - Aug-10-2021, 09:03 AM
RE: Windows compatibility - by buran - Aug-10-2021, 09:56 AM
RE: Windows compatibility - by Astrikor - Aug-10-2021, 10:03 AM
RE: Windows compatibility - by ndc85430 - Aug-10-2021, 10:14 AM
RE: Windows compatibility - by buran - Aug-10-2021, 10:21 AM
RE: Windows compatibility - by Astrikor - Aug-10-2021, 10:55 AM
RE: Windows compatibility - by buran - Aug-10-2021, 11:03 AM
RE: Windows compatibility - by Astrikor - Aug-10-2021, 11:27 AM
RE: Windows compatibility - by Luckk - Aug-10-2021, 01:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  deactivate compatibility pop up with excel files Krszt 0 1,945 Mar-19-2019, 06:39 AM
Last Post: Krszt
  Check Python version from inside script? Run Pythons script in v2 compatibility mode? pstein 2 9,875 Jul-07-2017, 08:59 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020