Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
logger behaviour
#1
This setup in python 3.10 is not logging DEBUG to log file.
As in the last line....rootLogger.debug("debugging MantisMigrateAdditionalInfo.py")
Why so?


for handler in logging.root.handlers[:]:
    logging.root.removeHandler(handler)
inputFileName="in.csv"
rootLogger = logging.getLogger("MantisMigrateAdditionalInfo")
rootLogger.setLevel(logging.DEBUG)
loggingFileName = inputFileName[0 : -4]
loggingFileName += "_additional.log"
logFormatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fileHandler = logging.FileHandler(filename=loggingFileName, mode='w')
fileHandler.setFormatter(logFormatter)
fileHandler.setLevel(logging.DEBUG)
rootLogger.addHandler(fileHandler)
consoleHandler = logging.StreamHandler(sys.stdout)
consoleHandler.setFormatter(logFormatter)
consoleHandler.setLevel(logging.INFO)
rootLogger.addHandler(consoleHandler)

rootLogger.info("starting MantisMigrateAdditionalInfo.py")
rootLogger.debug("debugging MantisMigrateAdditionalInfo.py")
Reply
#2
Your code works for me with Python 3.10.6 in Linux. Here is the contents of the log file.
Output:
2023-04-15 07:27:58,446 - MantisMigrateAdditionalInfo - INFO - starting MantisMigrateAdditionalInfo.py 2023-04-15 07:27:58,447 - MantisMigrateAdditionalInfo - DEBUG - debugging MantisMigrateAdditionalInfo.py
What does your logfile contain?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  can someone explain this __del__ behaviour? rjdegraff42 1 731 Apr-12-2023, 03:25 PM
Last Post: deanhystad
  Asyncio weird behaviour vugz 2 1,262 Apr-09-2023, 01:48 AM
Last Post: vugz
  Weird behaviour using if statement in python 3.10.8 mikepy 23 3,642 Jan-18-2023, 04:51 PM
Last Post: mikepy
  how to write exception error into logger mg24 3 991 Nov-15-2022, 04:20 PM
Last Post: insharazzak
  python insert blank line in logger mg24 1 2,862 Nov-02-2022, 08:36 AM
Last Post: snippsat
  python logger help ... save logger into different folder mg24 1 1,491 Oct-25-2022, 03:04 PM
Last Post: snippsat
  Generator behaviour bla123bla 2 1,111 Jul-26-2022, 07:30 PM
Last Post: bla123bla
  Closing logger from other function problem Paqqno 1 1,126 Apr-25-2022, 11:49 AM
Last Post: Gribouillis
  Closing logger to rename directory malcoverc 1 1,212 Apr-19-2022, 07:06 AM
Last Post: Gribouillis
  Inconsistent behaviour in output - web scraping Steve 6 2,564 Sep-20-2021, 01:54 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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