Skip to main content
← CoursesPython FoundationsModule 8 · Modern Python and capstonelogging — handlers, levels, formatterspredict164 / 170
💬 Discuss🧪 Playground+75 XP
Task
📝 **Question:** Predict the output of the snippet below. 📋 Pick the right answer. 💡 **Hint:** Re-read the theory above if unsure.

Keep going

🔮 Predict the output

Read the code carefully

import logging, io

buf = io.StringIO()
h = logging.StreamHandler(buf)
h.setFormatter(logging.Formatter("%(levelname)s:%(message)s"))

log = logging.getLogger("demo")
log.handlers.clear()
log.addHandler(h)
log.setLevel(logging.INFO)

log.debug("hidden")
log.info("hello")
print(buf.getvalue().strip())

What will the program print? Write here:

📣 Help someone learn PythonShare this lesson with a friend — the first 15 are free, no signup.Tweet

💬 Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…