Logging and configuration
Logging is the part you write last and need first. tracing gives you levels and spans; the
configuration around it — where the level comes from, which file wins over which environment
variable — is where the bugs are.
Short chapter, aimed at the moment your program works locally and not on the server.
Articles
Section titled “Articles”- How to add logging with tracinglevels, spans, and structured fields
- How to set the log level without recompilingRUST_LOG, and the default that hides everything
- How to log structured fieldskey=value, and the log you can actually query
- How to create a global with lazy initialisationOnceLock and LazyLock, no crate needed
- How to merge config from file, environment and flagsthe precedence order, written down once
- How to write a config file from a structserde out, and the diff a user will read
- How to keep secrets out of your logsredaction, and the debug print that leaked a token