Expand description
This crate provides an asynchronous logging backend that can direct logs to one or more outputs.
The core of this crate is the RingLog type, which is constructed using a
builder that is specific to your logging needs. After building the
RingLog, it can be registered as the global logger using the start
method. You will be left with a Box<dyn Drain> which should be
periodically flushed outside of any critical path. For example, in an admin
thread or dedicated logging thread.
For logging to a single file, the LogBuilder type can be used to construct
an RingLog which has low overhead, but directs log messages to a single
Output.
A SamplingLogBuilder can be used to construct an RingLog which will
filter the log messages using sampling before directing the log messages to
a single Output.
A MultiLogBuilder can be used to construct an RingLog which routes log
messages based on the target metadata of the log Record. If there is an
RingLog registered for that specific target, then the log message will
be routed to that instance of RingLog. Log messages that do not match any
specific target will be routed to the default RingLog that has been added
to the MultiLogBuilder. If there is no default, messages that do not match
any specific target will be simply dropped.
This combination of logging types allows us to compose a logging backend which meets the application’s needs. For example, you can use a local log macro to set the target to some specific category and log those messages to a file, while letting all other log messages pass to standard out. This could allow splitting command/access/audit logs from the normal logging.
Macros§
- debug
- Logs a message at the debug level.
- error
- Logs a message at the error level.
- fatal
- Logs a fatal error and terminates the program.
- info
- Logs a message at the info level.
- log
- The standard logging macro.
- log_
enabled - Determines if a message logged at the specified level in that module will be logged.
- trace
- Logs a message at the trace level.
- warn
- Logs a message at the warn level.
Structs§
- File
- A file based output which allows rotating the current log file off to a backup location.
- LogBuilder
- A type to construct a basic
RingLogwhich routes all log messages to a singleOutput. - Metadata
- Metadata about a log message.
- Metadata
Builder - Builder for
Metadata. - Multi
LogBuilder - A type to construct a multi-target
RingLogwhich routes messages based on the log’stargetmetadata to a correspondingRingLog. Targets which do not match a specific target will be routed to the defaultRingLogif one is configured. - NopLog
Builder - A type to construct a basic
RingLogwhich drops all log messages. - Parse
Level Error - The type returned by
from_strwhen the string doesn’t match any of the log levels. - Record
- The “payload” of a log message.
- Record
Builder - Builder for
Record. - RingLog
- A type which implements an asynchronous logging backend.
- Sampling
LogBuilder - A type to construct a basic
RingLogwhich routes 1 in N log messages to a singleOutput. - SetLogger
Error - The type returned by
set_loggerifset_loggerhas already been called. - Stderr
- An output that writes to
stderr. - Stdout
- An output that writes to
stdout.
Enums§
- Level
- An enum representing the available verbosity levels of the logger.
- Level
Filter - An enum representing the available verbosity level filters of the logger.
Constants§
- STATIC_
MAX_ LEVEL - The statically resolved maximum log level.
Traits§
- Drain
- A
Drainserves to receive log messages from a queue and flush them to anOutput. - Log
- A trait encapsulating the operations required of a logger.
- Output
- An
Outputis a logging destination, for example, standard out or a file.
Functions§
- default_
format - klog_
format - logger
- Returns a reference to the logger.
- max_
level - Returns the current maximum log level.
- set_
boxed_ logger - Sets the global logger to a
Box<Log>. - set_
logger - Sets the global logger to a
&'static Log. - set_
logger_ ⚠racy - A thread-unsafe version of
set_logger. - set_
max_ level - Sets the global maximum log level.
- set_
max_ ⚠level_ racy - A thread-unsafe version of
set_max_level.