Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ python main.py

Press **Esc** or close the window to quit.

### Debug logging

Run the emulator with verbose debug logs:

```bash
python main.py --debug
```


## UML Diagrams

Expand Down
13 changes: 12 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import argparse

from src.emulator.emulator import C64Emulator
from src.utils.log_setup import log
from src.utils.log_setup import setup_logging


def main() -> None:
parser = argparse.ArgumentParser(description="Commodore 64 Emulator")
parser.add_argument(
"--debug",
action="store_true",
help="Enable debug mode with more detailed logs",
)
args = parser.parse_args()

log = setup_logging(debug=args.debug)
emulator = C64Emulator()

try:
Expand Down
40 changes: 18 additions & 22 deletions src/utils/log_setup.py
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")

Comment on lines 26 to 31
Copy link
Copy Markdown

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 where multiprocessing uses the spawn start method (e.g. Windows), the bus worker process imports log_setup but never executes main(), so setup_logging(debug=…) is never invoked. As a result, all log.info/log.debug calls in the bus process (for example in Bus.__init__) run with the default WARNING level and no handlers, so the newly added --debug flag 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 👍 / 👎.

log: logging.Logger = setup_logging()
return log