book
book copied to clipboard
Book: Logging
logcrate: macros with similar syntax toprintln- crate for actual log output -- which one? env_logger?
I'm not a big fan of env_logger because you have to set a magic environment variable to get any output, which makes it difficult to integrate with the traditional --verbose and --quiet command-line arguments. The clap-verbosity-flag crate takes care of that, but that only works for one module; if you want to figure out what your program is really doing and turn up the logging verbosity everywhere, you're out of luck.
I've had good results with fern, although it doesn't integrate with clap out of the box.
Some command-line tools used as part of larger batch processes might have their logs fed into a rich data store like ElasticSearch or journald; in those cases, the slog crate and its ecosystem might be a better fit than the log crate, since it's designed around logging structured data rather than strings.