FaithLife-Community / LogosLinuxInstaller

A Python application that helps install and maintain FaithLife's Logos Bible (Verbum) Software on Linux through Wine.
MIT License
24 stars 8 forks source link

TUI python logging basicConfig is ignored in `msg.initialize_curses_logging` #135

Closed n8marti closed 1 month ago

n8marti commented 1 month ago

logging.basicConfig can typically only be called once unless force=True (see https://docs.python.org/3/library/logging.html#logging.basicConfig). This means that when msg.initialize_curses_logging is called, the handler is not actually changed in logging.basicConfig. I confirmed this by listing the handlers after both initialize_*logging fucntions were called, and it shows that the two handlers that are set in initialize_logging are retained after the call to initialize_curses_logging.

n8marti commented 1 month ago

I tried adding force=True to the call to logging.basicConfig, and I get a recursion error. Probably what needs to happen is that rather than call basicConfig again, the current logger should be modified; i.e. something like:

def initialize_curses_logging(stdscr):
    current_logger = logging.getLogger()
    current_handlers = current_logger.handlers
    for h in current_handlers:
        current_logger.removeHandler(h)
    current_logger.addHandler(CursesHandler(stdscr))
thw26 commented 1 month ago

Hitting recursion on trying this:

./main.py 
2024-07-23 11:07:29 ERROR: An error occurred in run_control_panel(): maximum recursion depth exceeded
Traceback (most recent call last):
  File "/home/thwright/Dev/LogosLinuxInstaller/./main.py", line 281, in run_control_panel
    curses.wrapper(tui_app.control_panel_app)
  File "/usr/lib/python3.12/curses/__init__.py", line 94, in wrapper
    return func(stdscr, *args, **kwds)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/thwright/Dev/LogosLinuxInstaller/tui_app.py", line 602, in control_panel_app
    TUI(stdscr).run()
  File "/home/thwright/Dev/LogosLinuxInstaller/tui_app.py", line 215, in run
    self.display()
  File "/home/thwright/Dev/LogosLinuxInstaller/tui_app.py", line 172, in display
    logging.debug(f"{current_handlers}")
  File "/usr/lib/python3.12/logging/__init__.py", line 2226, in debug
    root.debug(msg, *args, **kwargs)
  File "/usr/lib/python3.12/logging/__init__.py", line 1527, in debug
    self._log(DEBUG, msg, args, **kwargs)
  File "/usr/lib/python3.12/logging/__init__.py", line 1684, in _log
    self.handle(record)
  File "/usr/lib/python3.12/logging/__init__.py", line 1700, in handle
    self.callHandlers(record)
  File "/usr/lib/python3.12/logging/__init__.py", line 1762, in callHandlers
    hdlr.handle(record)
  File "/usr/lib/python3.12/logging/__init__.py", line 1028, in handle
    self.emit(record)
  File "/home/thwright/Dev/LogosLinuxInstaller/msg.py", line 23, in emit
    status(msg)
  File "/home/thwright/Dev/LogosLinuxInstaller/msg.py", line 236, in status
    logging.debug(f"Status: {text}")
  File "/usr/lib/python3.12/logging/__init__.py", line 2226, in debug
    root.debug(msg, *args, **kwargs)
  File "/usr/lib/python3.12/logging/__init__.py", line 1527, in debug
    self._log(DEBUG, msg, args, **kwargs)
  File "/usr/lib/python3.12/logging/__init__.py", line 1684, in _log
    self.handle(record)
  File "/usr/lib/python3.12/logging/__init__.py", line 1700, in handle
    self.callHandlers(record)
  File "/usr/lib/python3.12/logging/__init__.py", line 1762, in callHandlers
    hdlr.handle(record)
  File "/usr/lib/python3.12/logging/__init__.py", line 1028, in handle
    self.emit(record)
  File "/home/thwright/Dev/LogosLinuxInstaller/msg.py", line 23, in emit
    status(msg)
  File "/home/thwright/Dev/LogosLinuxInstaller/msg.py", line 236, in status
    logging.debug(f"Status: {text}")