Module env_logger

Source
Expand description

A simple logger that can be configured via environment variables.


env_logger is a logging implementation for the log facade that filters log messages based on environment variables. It’s the most commonly used logging backend in the Rust ecosystem, particularly for command-line applications.

By default, env_logger reads the RUST_LOG environment variable to determine which log messages to display. The format is target=level, where target can be a module path and level is one of error, warn, info, debug, or trace.

§Examples

Initialize the logger at the start of your program:

use log::info;

fn main() {
    env_logger::init();

    info!("Starting application");
}

Modules§

fmt
Formatting for log records.

Structs§

Builder
Builder acts as builder for initializing a Logger.
Env
Set of environment variables to configure from.
Logger
The env logger.

Enums§

Target
Log target, either stdout, stderr or a custom pipe.
TimestampPrecision
Formatting precision of timestamps.
WriteStyle
Whether or not to print styles to the target.

Constants§

DEFAULT_FILTER_ENV
The default name for the environment variable to read filters from.
DEFAULT_WRITE_STYLE_ENV
The default name for the environment variable to read style preferences from.

Functions§

builder
Create a new builder with the default environment variables.
from_envDeprecated
Create a builder from the given environment variables.
init
Initializes the global logger with an env logger.
init_from_env
Initializes the global logger with an env logger from the given environment variables.
try_init
Attempts to initialize the global logger with an env logger.
try_init_from_env
Attempts to initialize the global logger with an env logger from the given environment variables.