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

Add flexi_logger to the dependencies in your project's Cargo.toml.

[dependencies]
flexi_logger = "0.6"
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

   use flexi_logger::Logger;

   Logger::with_str("modx::mody = info")
       // ... your configuration options go here ...
       .start()
       .unwrap_or_else(|e| panic!("Logger initialization failed with {}", e));

The configuration options allow e.g. to

  • decide whether you want to write your logs to stderr or to a file,
  • configure the filenames and the folder in which the log files are created,
  • specify the line format for the log lines

See Logger 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 [
Deprecated
]

Deprecated. Use Logger instead.

LogRecord

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

LogSpecBuilder

Builder for LogSpecification.

LogSpecification

Immutable struct that defines which loglines are to be written, based on the module, the log level, and the text.

Logger

The standard entry-point for using flexi_logger.

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 [
Deprecated
]
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.