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")

# am trialling this to stop messages being lost on a giant run over midnight
logger.add("logs/1trace.log", level="TRACE", rotation="100 MB")

# 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

I have seen it not rotate at midnight when it was stuck in a giant job which went on from 2200 until 0900.

Top level handler

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