-
Notifications
You must be signed in to change notification settings - Fork 2
Refactor logging setup for debug flag #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1,32 @@ | ||
| import argparse | ||
| import logging | ||
|
|
||
| log: logging.Logger = logging.getLogger("C64Emulator") | ||
|
|
||
| def setup_logging() -> logging.Logger: | ||
| """ | ||
| Configures global logging for the Commodore 64 Emulator. | ||
|
|
||
| :return: Configured logger instance. | ||
| def setup_logging(*, debug: bool = False) -> logging.Logger: | ||
| """ | ||
| parser: argparse.ArgumentParser = argparse.ArgumentParser( | ||
| description="Commodore 64 Emulator Logging Setup" | ||
| ) | ||
| parser.add_argument( | ||
| "--debug", | ||
| action="store_true", | ||
| help="Enables debug mode with more detailed logs", | ||
| ) | ||
| args, _ = parser.parse_known_args() | ||
| Configure global logging for the Commodore 64 Emulator. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| debug: bool | ||
| Enables debug mode with more detailed logs. | ||
|
|
||
| debug_enabled: bool = args.debug | ||
| level: int = logging.DEBUG if debug_enabled else logging.INFO | ||
| Returns | ||
| ------- | ||
| logging.Logger | ||
| Configured logger instance. | ||
|
|
||
| """ | ||
| level: int = logging.DEBUG if debug else logging.INFO | ||
|
|
||
| logging.basicConfig( | ||
| level=level, | ||
| format="%(asctime)s - %(levelname)s - %(message)s", | ||
| datefmt="%Y-%m-%d %H:%M:%S", | ||
| ) | ||
|
|
||
| logger: logging.Logger = logging.getLogger("C64Emulator") | ||
| logger.info("Logging configured") | ||
|
|
||
| return logger | ||
|
|
||
| log.setLevel(level) | ||
| log.info("Logging configured") | ||
|
|
||
| log: logging.Logger = setup_logging() | ||
| return log | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] Configure logging in multiprocessing child processes
Removing the module‑level
setup_logging()call means the logger is never configured when a new process starts. On platforms wheremultiprocessinguses thespawnstart method (e.g. Windows), the bus worker process importslog_setupbut never executesmain(), sosetup_logging(debug=…)is never invoked. As a result, alllog.info/log.debugcalls in the bus process (for example inBus.__init__) run with the default WARNING level and no handlers, so the newly added--debugflag does not emit any logs from the core emulator. Consider configuring logging inside each process or restoring an import‑time initialization so child processes honour the debug flag.Useful? React with 👍 / 👎.