Crate flexi_logger [] [src]

A logger that can write the log to standard error or to a fresh file in a configurable folder and allows custom logline formats. It had started as an extended copy of env_logger.

Usage

This crate is on crates.io and can be used by adding flexi_logger to the dependencies in your project's Cargo.toml.

[dependencies]
flexi_logger = "^0.5.1"
log = "*"

and this to your crate root:

extern crate flexi_logger;
#[macro_use]
extern crate log;

The latter is needed because flexi_logger plugs into the standard Rust logging facade given by the log crate, and you use the log macros to write log lines from your code.

Early in the start-up of your program, call something like

   flexi_logger::LogOptions::new()
       .log_to_file(true)
       // ... your configuration options go here ...
       .init(Some("info".to_string()))
       .unwrap_or_else(|e| panic!("Logger initialization failed with {}", e));

The configuration options allow e.g. to

See LogOptions for a full description of all configuration options.

Structs

FlexiLogger

Does the logging in the background, is normally not used directly.

LogConfig

Internal struct for influencing the behavior of flexi_logger.

LogOptions

Allows initializing flexi_logger to your needs.

LogRecord

The "payload" of a log message. This structure is primarily used as a parameter in the log method of the Log trait.

Enums

FlexiLoggerError

Describes errors in the initialization of flexi_logger.

LogLevel

An enum representing the available verbosity levels of the logging framework.

LogLevelFilter

An enum representing the available verbosity level filters of the logging framework.

Functions

default_format

A logline-formatter that produces log lines like
INFO [my_prog::some_submodule] Task successfully read from conf.json

detailed_format

A logline-formatter that produces log lines like
[2016-01-13 15:25:01.640870 +01:00] INFO [foo::bar] src/foo/bar.rs:26: Task successfully read from conf.json
i.e. with timestamp, module path and file location.

init

Initializes the flexi_logger to your needs, and the global logger with flexi_logger.

opt_format

A logline-formatter that produces log lines like
[2016-01-13 15:25:01.640870 +01:00] INFO [src/foo/bar:26] Task successfully read from conf.json
i.e. with timestamp and file location.

with_thread

A logline-formatter that produces log lines like
[2016-01-13 15:25:01.640870 +01:00] T[taskreader] INFO [src/foo/bar:26] Task successfully read from conf.json
i.e. with timestamp, thread name and file location.