18.1. Logging About

  • Do not print

  • Always use logger

  • Logs can be displayed on console

  • Logs can be redirected to file

  • Logs can be redirected to database

  • Logs can be silenced (certain level)

  • Logs can be rotated

  • Logs can change format

import logging


def run():
    logging.warning('Program start')
    for number in range(0,3):
        logging.info(f'Current number: {number}')
    logging.warning('Program end')


run()
WARNING:root:Program start
WARNING:root:Program end

18.1.1. Further Reading