Crate flexi_logger[][src]

A logger that writes logs to stderr or to a fresh file, or to a sequence of files, in a configurable folder. It allows custom logline formats, and it allows changing the log specification at runtime. It further allows defining additional log streams, e.g. for alert or security messages.

As it had started as an extended copy of env_logger, it is still using a similar syntax for specifying which logs should really be written.

Usage

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

[dependencies]
flexi_logger = "0.8"
log = "0.4"

or, if you want to use the specfile feature, with

[dependencies]
flexi_logger = { version = "0.8", features = ["specfile"] }
log = "0.4"

and add this to your crate root:

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

log 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_env_or_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 default logs to stderr or to a file,
  • configure the filenames and the folders in which the log files are created,
  • specify the line format for the log lines
  • define additional log writers, e.g for special log types.

See Logger for a full description of all configuration options, and the writers module for the usage of additional log writers.

See Change log for details of the previous versions.

Modules

writers

This module contains a trait for additional log writers, and a configurable concrete implementation for a log writer that writes to a file or a series of files.

Structs

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.

ReconfigurationHandle

Allows reconfiguring the logger while it is in use (see Logger::start_reconfigurable() ).

Record

The "payload" of a log message.

Enums

FlexiLoggerError

Describes errors in the initialization of flexi_logger.

Level

An enum representing the available verbosity levels of the logger.

LevelFilter

An enum representing the available verbosity level filters of the logger.

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.

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.

Type Definitions

FormatFunction

Function type for Format functions.