Good logging is important in production to diagnose issues.

loguru is a python logging library

# pip install loguru

from loguru import logger

# outputs to stderr by default
logger.debug("That's it, beautiful and simple logging!")

Standard logging levels and trace and success. When to Use different levels

  • trace - used when tracing code
  • debug.. eg program level.. args passed in, up. Helpful to more than just developers.
  • info. eg business logic eg trying archiver.
  • success.. eg youtube archiver succeeded
  • warning.. eg twitterarchiver can’t get tweet (and then goes to wayback).
  • error eg incorrect connection strings
  • critical

Log Warnings and above to separate file

docs

logger.add("trace.log", level="TRACE")
logger.add("warnings.log", level="WARNING")

Top level handler

# loguru catchall decorator
@logger.catch
def main():