Expand description
A lightweight, flexible logging framework for Rust applications.
This crate provides a configurable logging system that supports multiple output targets, customizable formatting, and different log levels. It can be used in both synchronous (blocking) and asynchronous contexts.
§Features
- Multiple log levels (Debug, Info, Warning, Error)
- Multiple output targets (Console, File)
- Customizable log formatting
- Async and blocking implementations
§Example
ⓘ
use logger::{init, LogLevel};
// Initialize with Info level
init(LogLevel::Info);
// Log messages
info!("Application started");
debug!("This won't be displayed with Info level");
error!("Something went wrong: {}", error);Macros§
- debug
- Logs a message at the DEBUG level.
- error
- Logs a message at the ERROR level.
- fatal
- Logs a message at the FATAL level.
- info
- Logs a message at the INFO level.
- log
- Macro for logging messages at a specific level.
- span
- Creates a new span with the given name and fields.
- trace
- Logs a message at the TRACE level.
- warn
- Logs a message at the WARN level.
Structs§
- Config
- Configuration for initializing a logger.
- Console
- Standard console output target.
- Default
Formatter - Default log message formatter with configurable span positioning.
- Default
Logger - File
- File output target.
- Formatter
Builder - Helper builder for creating custom formatters with span positioning support.
- Record
- Represents a single log record with all relevant metadata.
- Span
- Represents a single span with a name and key-value pairs.
- Span
Guard - A guard that represents an active span.
Enums§
- Color
- Terminal colors for text output.
- Error
- File
Mode - File open mode for writing log messages.
- Hook
- Represents a hook that can be set to trigger at specific points in the logging process.
- LogLevel
- Logging severity levels in ascending order of importance.
- Output
- Output destination for console log messages.
- Span
Position - Position where span context should appear in log messages.
- Target
Id - Represents the id of the target where the log message is written. This can be a console output, file path, or a custom string identifier. Useful for identifying the target in hooks / filters.
Traits§
- Colorize
- Trait for applying colors to strings.
- Formatter
- Defines a log message formatter.
- Logger
- Core trait that defines the logging behavior.
- Style
- Target
- Defines an output destination for log messages.
Functions§
- current_
context - Returns the current span context as a vector of (span_name, key=value) pairs.
- enter
- Enters a new span with the given name and fields.
- format_
span_ context - Formats span context into a string with default formatting.
- format_
span_ context_ with - Formats span context with a custom formatter function.
- format_
with_ span_ position - Helper function to format a record with span context at the specified position.
- init
- Initializes the global logger with the specified minimum log level.
- init_
default - Initializes the global logger with default settings.
- init_
with_ config - Initializes the global logger with a custom configuration.
- logger
- Retrieves the global logger instance.
- parse_
level_ from_ env - Checks the
RUST_LOGenv variable and tries to parse its value - set_
hook - Sets a hook to be called at the specified point in the logging process.