Configured File Logger
Configure logging to write to a file app.log (without a timestamp in the format, so the output stays exactly reproducible), then log one message at each of the 5 severity levels, and print back what actually landed in the file.
Why no timestamp? including %(asctime)s would make the file's content different every time it runs (down to the millisecond), which an exact-match judge can never grade — so this problem uses a format of just the level name and the message, which the notes themselves show is fully configurable.
Approach: logging.basicConfig(filename="app.log", level=<threshold>, format="%(levelname)s - %(message)s"), log one message at each level, then read the file back and print its contents — only messages at or above the configured threshold should actually appear.
Input: One line: the threshold level name (one of DEBUG, INFO, WARNING, ERROR, CRITICAL).
Output: The contents of app.log — one line per message at or above the given threshold, in level order.
WARNING
WARNING - Warning message ERROR - Error message CRITICAL - Critical message
- threshold is always one of DEBUG, INFO, WARNING, ERROR, CRITICAL.
Hint 1
getattr(logging, threshold) converts the threshold TEXT (like "WARNING") into the actual logging.WARNING constant.
Hint 2
Only messages at the configured level or more severe are actually written to the file — everything below the threshold is silently dropped.
Hint 3
Reopen app.log in read mode after logging, and print its full content.
logging.basicConfig(filename="app.log", level=..., format="%(levelname)s - %(message)s") routes every logging call into the file, formatted as just the level name and message (no timestamp, so the output stays exactly reproducible). Only messages at or above the configured threshold are actually written — five logging calls, one per level, then reading the file back shows exactly which of them cleared the bar.