Crate flexi_logger
source ·Expand description
A flexible and easy-to-use logger that writes logs to stderr and/or to files or other output streams.
To read the log specification from an environment variable and get the log written to stderr,
start flexi_logger e.g. like this:
flexi_logger::Logger::try_with_env().unwrap().start().unwrap();See
- The builder
Loggerfor a full description of all configuration options, - module
code_examplesfor various concrete examples offlexi_loggerinitialization - the module
writersfor the usage of additional log writers, - and the README for how to get started.
There are configuration options to e.g.
- decide whether you want to write your logs to stderr or to a file,
- configure the path and the filenames of the log files,
- use file rotation,
- specify the line format for the log lines,
- apply a stateful filter before log lines are really written,
- define additional log output streams, e.g for alert or security messages,
- support changing the log specification while the program is running,
flexi_logger uses a similar syntax as env_logger
for specifying which logs should really be written (but is more graceful with the syntax,
and can provide error information).
By default, i.e. if feature colors is not switched off, the log lines that appear on your
terminal are coloured. In case the chosen colors don’t fit to your terminal’s color theme,
you can adapt the colors to improve readability.
See the documentation of method Logger::set_palette
for a description how this can be done.
Modules
flexi_logger initialization.flexi_logger.Logger::filter.LogWriter for extending flexi_logger
with additional log writers,
and two concrete implementations
for writing to files (FileLogWriter)
or to the syslog (SyslogWriter).
You can also use your own implementations of LogWriter.Structs
LogSpecification.flexi_logger.LoggerHandle::clone() you can have multiple instances),
and allows reconfiguring the logger programmatically.Enums
attyLogger::adaptive_format_for_stderr and
Logger::adaptive_format_for_stdout
to use coloring only if the output goes to a tty.Criterion::Age is chosen.log_to_file() is used.flexi_logger’s own error messages.flexi_logger.Constants
asyncasyncFunctions
colorsdefault_format
that produces log lines like ERROR [my_prog::some_submodule] File not foundcolorsdetailed_format.colorsopt_format.colorswith_thread.INFO [my_prog::some_submodule] Task successfully read from conf.json[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.
[2016-01-13 15:25:01.640870 +01:00] INFO [src/foo/bar:26] Task successfully read from conf.json
colors[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.