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
.
[dependencies]
flexi_logger = "0.7"
log = "0.4"
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_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.
Modules
deprecated |
Package for deprecated structs etc. These will be removed or made internal in one of the next versions (let us know if this would cause difficulties). |
writers |
A trait for additional log writers, and a configurable concrete implementation for a log writer writing to a file or a series of files. |
Structs
LogSpecBuilder |
Builder for |
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 |
ReconfigurationHandle |
Allows reconfiguring the logger while it is in use
(see |
Record |
The "payload" of a log message. |
Enums
FlexiLoggerError |
Describes errors in the initialization of |
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 |
detailed_format |
A logline-formatter that produces log lines like
|
opt_format |
A logline-formatter that produces log lines like
|
with_thread |
A logline-formatter that produces log lines like
|