Aller au contenu

Structured Logging (ARCH2158)

Ce contenu n’est pas encore disponible dans votre langue.

Key python.logging.structured-logging · Severity info · Category logging

Using string interpolation or concatenation in log calls makes it harder for log aggregation systems to group and search messages. Parameterized templates keep variables as separate fields.

logger.info("User " + user.id + " logged in, ip=" + ip)
logger.info("User logged in", extra={"user_id": user.id, "ip": ip})

Keep the message template constant and pass variables as parameters or extra fields.