Bug hunt

The Quiet Logbook

print is fine for quick checks, but real programs use logging. Every message has a level, and you choose which levels to show:

DEBUG < INFO < WARNING < ERROR < CRITICAL

import logging, sys

logging.basicConfig(level=logging.INFO, stream=sys.stdout,
                    format="%(levelname)s:%(name)s:%(message)s",
                    force=True)
log = logging.getLogger("depot")

log.debug("hidden: below INFO")
log.info("Loaded %d crates", 3)    # INFO:depot:Loaded 3 crates
  • level= hides every message below that level.
  • Pass values as extra arguments ("%d crates", 3). Every % placeholder needs a matching value.
  • stream=sys.stdout sends logs to PyQuest's output panel, and force=True replaces any setup from an earlier run. In a real app you call basicConfig once, at startup.

The bug report

The depot's log should show:

INFO:depot:Loading 3 crates
ERROR:depot:Crate wick has negative qty -2
Total: 9

Instead, the INFO line never appears. And the error turns into a scary --- Logging error --- message.

Assignment

Fix the two bugs:

  1. Change the level in basicConfig so INFO messages are shown.
  2. Fix the log.error(...) call so every % placeholder gets a value.

The program should then print exactly the three lines above.