Skip to main content

Crate logforth_filter_rustlog

Crate logforth_filter_rustlog 

Source
Expand description

A filter that follows the famous RUST_LOG directive pattern.

Log levels are controlled on a per-module basis, and by default all logging is disabled except for the error level.

You can use RustLogFilterBuilder::from_default_env to configure the filter from the RUST_LOG environment variable, or RustLogFilterBuilder::from_spec to configure the filter by directly passing a specification string.

The specification string is a comma-separated list of logging directives. A logging directive is of the form:

target=level

target is typically path::to::module, but it may also be set manually via the log macros.

The path to the module is rooted in the name of the crate it was compiled for. Thus, if your program is contained in a file hello.rs, for example, to turn on logging for this file you would use a value of RUST_LOG=hello. Furthermore, this path is a prefix-search, so all modules nested in the specified module will also have logging enabled.

When providing the crate name or a module path, explicitly specifying the log level is optional. If omitted, all logging for the item (and its children) will be enabled.

The names of the log levels that may be specified correspond to the variations of the Level enum. The most common used levels include:

  • fatal
  • error
  • warn
  • info
  • debug
  • trace

There is also a pseudo logging level, off, which may be specified to disable all logging for a given module or for the entire application. As with the logging levels, the letter case is not significant; e.g., debug, DEBUG, and dEbuG all represent the same logging level.

As the log level for a module is optional, the module to enable logging for is also optional. If only a level is provided, then the global log level for all modules is set to this value.

Some examples of valid values are:

  • hello turns on all logging for the ‘hello’ module
  • trace turns on all logging for the application, regardless of its name
  • TRACE turns on all logging for the application, regardless of its name (same as previous)
  • info turns on all info logging
  • INFO turns on all info logging (same as previous)
  • hello=debug turns on debug logging for ‘hello’
  • hello=DEBUG turns on debug logging for ‘hello’ (same as previous)
  • hello,std::option turns on hello, and std’s option logging
  • error,hello=warn turns on global error logging and also warn for hello
  • error,hello=off turns on global error logging, but turn off logging for hello
  • off turns off all logging for the application
  • OFF turns off all logging for the application (same as previous)

Structs§

RustLogFilter
A filter consists of one or more comma-separated directives which match on Record.
RustLogFilterBuilder
A builder for RustLogFilter.

Constants§

DEFAULT_FILTER_ENV
The default environment variable for filtering logs.