3.1 KiB
Logging in IOx
Basic Usage
IOx can produce logs at various different levels of verbosity, this can be controlled in one of two ways:
- The
-v
option can be specified one or more times to increase the log verbosity through a set of pre-defined filters - A custom filter can be specified with
--log-filter
or theLOG_FILTER
environment variable
The full format filter format is described here
Some examples
# Default verbosity
$ ./influxdb_iox run all-in-one
# More verbose
$ ./influxdb_iox run all-in-one -v
# Even more verbose
$ ./influxdb_iox run all-in-one -vv
# Everything!!
$ ./influxdb_iox run all-in-one --log-filter trace
# Default info, but debug within http module
$ ./influxdb_iox run all-in-one --log-filter info,influxdb_iox::influxdb_ioxd::http=debug
Additionally, the output format can be controlled with --log-format
$ ./influxdb_iox run all-in-one --log-filter debug --log-format logfmt
Developer Guide
IOx makes use of Rust's tracing ecosystem to output application logs to stdout. It additionally makes use of tracing-log to ensure that crates writing events to the log facade are also rendered to stdout.
Macros
As described in the tracing documentation macros are
provided to log events, e.g. info!
, error!
. Additionally, spans can be created that add context to all events
contained within them1..
#[tracing::instrument]
fn say_hello(name: &str) {
// This is good - fields come first!
info!(name, "hello there");
// This is alright, but less structured / useful
info!("hello there {}", name);
}
Filtering
IOx makes use of tracing-subscriber::EnvFilter to selectively enable or disable log callsites at runtime. In most cases if a callsite is not enabled by the filter, it will not perform any string formatting and has minimal runtime overhead2..
This is exposed as the LOG_FILTER
environment variable, or the --log-filter
command line argument. The format is
described here.
Additionally compile time features are used
to strip out certain log levels from the final binary. At the time of writing release_max_level_debug
is in use, which
will strip out all trace level callsites from the release binary.
Format
IOx supports logging in many formats. For a list run influxdb_iox run --help
and view the help output
for --log-format
.
1. This span propagation uses thread-local storage and therefore does not automatically carry across
thread-boundaries (e.g. tokio::spawn
)
2. Filters dependent on an event's attributes, called dynamic filters, will still perform attribute formatting, even if the log is later discarded, unless a non-dynamic filter allows skipping the callsite entirely