Closed n8marti closed 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))
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}")
logging.basicConfig
can typically only be called once unlessforce=True
(see https://docs.python.org/3/library/logging.html#logging.basicConfig). This means that whenmsg.initialize_curses_logging
is called, the handler is not actually changed inlogging.basicConfig
. I confirmed this by listing the handlers after bothinitialize_*logging
fucntions were called, and it shows that the two handlers that are set ininitialize_logging
are retained after the call toinitialize_curses_logging
.