runtime
232 / 500
question 232 Debugging & Logging · easy

Warnings that never reach the log

invalid_codes returns the barcodes that aren't 8 or 13 digits, and is meant to log a WARNING naming each bad product. The nightly job runs at WARNING level and its log has never shown one, although the returned list is right. Run the starter (it sets the level to DEBUG and prints the log to the console), read what logging itself reports, and fix the logging call.

Functioninvalid_codes(products), using the logger log = logging.getLogger("barcodes")
Returnsthe codes that are not all digits with length 8 or 13, in order
Logsone WARNING per bad product: product <name> has invalid code <code>
Examples
callinvalid_codes([{'code': '3017620422003', 'name': 'Nutella'}, {'code': '30176', 'name': 'Hazelnut spread'}, {'code': '5449000000996', 'name': 'Coca-Cola'}, {'code': '87157239', 'name': 'Gouda slices'}])returns['30176']

Loading your progress…

Warnings that never reach the log — Python practice · Runtime