feat(logger): overhaul logging system with module-aware names and c…#186
Merged
feat(logger): overhaul logging system with module-aware names and c…#186
Conversation
…ash handling
- Replace AsyncFileHandler with ThreadedFileHandler (queue + background
thread wrapping TimedRotatingFileHandler; "async" was a misnomer)
- Add LogManager singleton: configures root logger, optional
StreamToLogger capture of stderr/stdout, handler deduplication
- Add CrashHandler: installs sys.excepthook, threading.excepthook, and
faulthandler for C-level crashes; supports exit_on_crash flag
- Expose setup_logging() and get_logger() as the public API
- Suppress noisy third-party loggers (urllib3, websocket, PIL) to WARNING
- Fix all modules to use logging.getLogger(__name__) instead of the old
named-file pattern (logs/BlocksScreen.log):
BlocksScreen.py, configfile.py, lib/machine.py, lib/moonrest.py,
lib/printer.py, lib/panels/mainWindow.py,
lib/panels/widgets/connectionPage.py
- Replace manual logger-iteration loop in MainWindow.closeEvent with
LogManager.shutdown(); remove erroneous recursive self.close() call
- Fix create_hotspot password param: str | None = None, raise ValueError
instead of silently accepting empty/hardcoded default (bandit B107)
- Replace all bare except/pass blocks with typed exception handling that
writes to sys.__stderr__ when the logger itself may be unavailable
(bandit B110)
EOF
)"
…er → ThreadedFileHandler chain
…' into bugfix/logger-clean
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.
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