Pcornel
Automation · Python Automation

Logging

Cheat sheet · https://pcornel.dk/topic.php?topic=5262

Back to the Topic

Answer

Python logging uses the logging module with levels (DEBUG to CRITICAL), handlers and formatters, so automation writes timestamped logs to files or syslog instead of print statements.

Remember

  • Use the logging module, not print.
  • Levels: DEBUG, INFO, WARNING, ERROR, CRITICAL.
  • Handlers send logs to files or syslog.

First checks

  • python3 -c 'import logging; logging.basicConfig(level=logging.INFO); logging.info("ok")' — basic logging
  • Log format with timestamp and level — consistency
  • No secrets in logs — security

Verify in this order

code → logger → handlers → output

Where it usually breaks

Input/desired state → request accepted → job/task terminal status → target object read-back → effective runtime state → original workload → regression/rollback readiness.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5262

Confirmation

Confirm action

Continue?