fix: overhaul logging system with proper module names and crash handling#184
Closed
gmmcosta15 wants to merge 12 commits intodevfrom
Closed
fix: overhaul logging system with proper module names and crash handling#184gmmcosta15 wants to merge 12 commits intodevfrom
gmmcosta15 wants to merge 12 commits intodevfrom
Conversation
Signed-off-by: Hugo Costa <hugo.santos.costa@gmail.com>
…sh handling
Replace the old single-named logger pattern (logs/BlocksScreen.log) with
standard Python logging conventions across the entire codebase.
logger.py:
- Add LogManager: configures the root logger once at startup; all modules
then use logging.getLogger(__name__) with no extra setup
- Add ThreadedFileHandler (replaces QueueListener): TimedRotatingFileHandler
backed by a queue + daemon thread for non-blocking writes; recovers if
log file is deleted at runtime
- Add CrashHandler: installs sys.excepthook and threading.excepthook to
write detailed crash logs (traceback, locals, thread list) to disk;
uses faulthandler for C-level crashes (segfaults); daemon threads are
exempt from os._exit(1)
- Add StreamToLogger: redirects stderr (X11 errors, Qt warnings) to the
logger without losing the original stream
- Add setup_logging() entry point used by BlocksScreen.py
- Fix: remove redundant _lock from ThreadedFileHandler.emit()
(TimedRotatingFileHandler already holds its own lock)
- Fix: add types.TracebackType | None annotation to _exception_hook
- Fix: warn instead of silently return when root logger already has handlers
Module fixes (logging.getLogger(__name__) everywhere):
- configfile.py, lib/machine.py, lib/moonrest.py, lib/network.py,
lib/printer.py, lib/panels/networkWindow.py,
lib/panels/widgets/connectionPage.py
…er' into bugfix/logger-manager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Select the type:
Replaces the broken single-named logger pattern (logging.getLogger("logs/BlocksScreen.log")) and bare logging.error() / logging.debug() calls.
auto-recovers if the log file is deleted at runtime.
active thread list) to disk on unhandled exceptions; uses faulthandler for C-level crashes (segfaults); daemon threads are exempt from
os._exit(1).
lib/panels/networkWindow.py, lib/panels/widgets/connectionPage.py.
Motivation
The old logging setup used logging.getLogger("logs/BlocksScreen.log") as the logger name in every module. This caused all log output to show
logs/BlocksScreen.log as the source instead of the actual module name, making it impossible to trace which module emitted a given log line.
Additionally, several modules called logging.error() / logging.debug() directly, routing through the root logger and showing root in output.
This PR establishes the standard Python pattern: one setup_logging() call at startup configures the root logger, and every module independently
calls logging.getLogger(name) — zero coupling to the logging infrastructure. The result is accurate module names in every log line (e.g. lib.panels.networkWindow, lib.moonrakerComm) which makes debugging and production log analysis significantly faster.
The CrashHandler addition addresses production incidents where the application exits silently on unhandled exceptions or segfaults with no
recoverable information in the log files.
Screenshots
[INFO] | 2026-03-03 12:04:27,445 | logger | MainThread : Logging initialized
[INFO] | 2026-03-03 12:04:27,445 | main | MainThread : ============ BlocksScreen Initializing ============
[INFO] | 2026-03-03 12:04:27,570 | lib.moonrakerComm | MainThread : Websocket object initialized
[DEBUG] | 2026-03-03 12:04:27,993 | lib.panels.widgets.connectionPage | MainThread : [ConnectionWindowPanel] text_update: 1
[INFO] | 2026-03-03 12:04:28,029 | lib.moonrakerComm | websocket.run_forever : Connection to websocket achieved
Future work