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
Logger
for a full description of all configuration options, - module
code_examples
for various concrete examples offlexi_logger
initialization - the module
writers
for 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§
- Examples for the
flexi_logger
initialization. - Error codes of
flexi_logger
. - This module contains two traits which allow adding a stateful filter using
Logger::filter
. - trc
trc
Useflexi_logger
functionality withtracing
. - Describes how to extend
flexi_logger
with additional log writers.
Structs§
- Deferred timestamp creation.
- Builder object for specifying the name and path of the log output file.
- Builder for
LogSpecification
. - Immutable struct that defines which loglines are to be written, based on the module, the log level, and the text.
- Used in
LoggerHandle::existing_log_files
. - The entry-point for using
flexi_logger
. - Allows reconfiguring the logger while the program is running, and shuts down the logger when it is dropped.
- Defines which loglevel filter to use for the specified module.
- Re-exports from log crate The “payload” of a log message.
Enums§
- Helps to use coloring only if the output goes to a tty.
- The age after which a log file rotation will be triggered, when
Criterion::Age
is chosen. - Defines the strategy for handling older log files.
- Criterion when to rotate the log file.
- Used to control which messages are to be duplicated to stderr, when
log_to_file()
is used. - Enum for defining the output channel for
flexi_logger
’s own error messages. - Describes errors in the initialization of
flexi_logger
. - Re-exports from log crate An enum representing the available verbosity levels of the logger.
- Re-exports from log crate An enum representing the available verbosity level filters of the logger.
- The naming convention for rotated log files.
- Describes whether the log output should be written synchronously or asynchronously, and if and how I/O should be buffered and flushed.
Constants§
- Default buffer capacity (8k), when buffering is used.
- Default flush interval (1s), when flushing is used.
- Default capacity for the message buffers; a higher value reduces allocations when longer log lines are used.
- Default size of the message pool; a higher value could further reduce allocations during log file rotation and cleanup.
- Time stamp format that is used by the provided format functions.
Functions§
- colored_
default_ format colors
A colored version of the logline-formatterdefault_format
. - colored_
detailed_ format colors
A colored version of the logline-formatterdetailed_format
. - colored_
opt_ format colors
A colored version of the logline-formatteropt_format
. - colored_
with_ thread colors
A colored version of the logline-formatterwith_thread
. - A logline-formatter that produces log lines like
INFO [my_prog::some_submodule] Task successfully read from conf.json
. - 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
- Shortest form to get started.
- json_
format json
A logline-formatter that produces log lines in json format. - A logline-formatter that produces log lines with timestamp and file location, like
[2016-01-13 15:25:01.640870 +01:00] INFO [src/foo/bar:26] Task successfully read from conf.json
- style
colors
Helper function that is used in the provided coloring format functions to apply colors based on the log level and the effective color palette. - 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
Type Aliases§
- Function type for format functions.