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

# On Azure something bad happens around 700 MB file size
# new file created at midnight
# old file renamed 
logger.add("logs/1trace.log", level="TRACE", rotation="00:00")
# then debug
# logger.add("logs/2info.log", level="INFO")
# logger.add("logs/3success.log", level="SUCCESS")
# logger.add("logs/4warning.log", level="WARNING")
# logger.add("logs/5error.log", level="ERROR")
# then critical

Top level handler

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