Interview Prep/Python for DevOps/Exceptions, context managers, files & logging

Why use `logging` instead of `print`?

BeginnerConceptExceptions, context managers, files & logging
Answer

logging gives you levels (DEBUG, INFO, WARNING, ERROR, CRITICAL) you can change without editing code, timestamps and logger names, output to stderr so stdout stays clean for data, handlers for files/syslog/JSON, and library logs (boto3, urllib3) in the same stream. print gives none of that and mixes diagnostics with the report a pipeline might be parsing.

All Python for DevOps questions Roadmap: Python for automation

More on Exceptions, context managers, files & logging