Expand description
A flexible and efficient logging library for Rust.
This library provides a powerful logging system with the following features:
- Multiple log levels (TRACE, DEBUG, INFO, WARNING, ERROR, CRITICAL)
- Thread-safe global logger
- Extensible handler system
- Configurable log formatting
- Support for metadata in log records
- Convenient logging macros
- Asynchronous logging with worker thread pool
- Log crate compatibility
- Compile-time filtering optimizations
§Examples
use rust_loguru::{Logger, LogLevel, Record};
use rust_loguru::handler::NullHandler;
use rust_loguru::{info, debug, error};
use std::sync::Arc;
use parking_lot::RwLock;
// Create a logger with a handler
let handler = Arc::new(RwLock::new(NullHandler::new(LogLevel::Info)));
let mut logger = Logger::new(LogLevel::Debug);
logger.add_handler(handler);
// Log a message
let record = Record::new(
LogLevel::Info,
"Hello, world!",
Some("my_module".to_string()),
Some("main.rs".to_string()),
Some(42),
);
logger.log(&record);
// Or use the convenient macros
info!("Hello, world!");
debug!("Debug message: {}", 42);
error!("Error occurred: {}", "something went wrong");
// Asynchronous logging
logger.set_async(true, Some(10000));
info!("This will be logged asynchronously");
Re-exports§
pub use config::LoggerConfig;
pub use config::LoggerConfigBuilder;
pub use error::error_chain;
pub use error::install_panic_hook;
pub use error::ContextError;
pub use error::OptionExt;
pub use error::ResultExt;
pub use formatters::json::JsonFormatter;
pub use formatters::template::TemplateFormatter;
pub use formatters::text::TextFormatter;
pub use formatters::FormatterTrait;
pub use handler::Handler;
pub use level::LogLevel;
pub use logger::global;
pub use logger::init;
pub use logger::log;
pub use logger::Logger;
pub use record::Record;
pub use record_pool::PooledRecord;
pub use record_pool::RecordPool;
pub use scope::ScopeError;
pub use scope::ScopeGuard;
Modules§
- benchmark
- Module for benchmarking tools
- compile_
time - Module for compile-time filtering optimizations
- config
- context
- Context management for rust-loguru
- error
- Error handling utilities for rust-loguru
- formatter
- formatters
- handler
- integration
- Integration module for rust-loguru
- level
- log_
adapter - Module for log crate compatibility
- logger
- record
- record_
pool - scope
- Scope management for rust-loguru
- test_
utils - Test utilities for Rust-Loguru
Macros§
- assert_
log_ contains - Assertion macro for log capture
- assert_
log_ level - Assertion macro for log level
- compile_
time_ level_ enabled - Compile-time level check
- critical
- Logs a message at the CRITICAL level.
- debug
- Logs a message at the DEBUG level.
- debug_
println - Debug print macro that only prints when the debug_logging feature is enabled
- error
- Logs a message at the ERROR level.
- get_
context - Get a value from the current context.
- info
- Logs a message at the INFO level.
- info_kv
- log_
error - Log an error with source location (uses error! macro)
- log_
error_ with_ context - Log an error with context (uses error! macro)
- log_
error_ with_ location - Helper to log an error with source location
- log_
if_ enabled - log_
with_ metadata - Logs a message with metadata at the specified level.
- pop_
context - Pop the top context map from the stack.
- push_
context - Push a new context map onto the stack. Usage: push_context! { “key1” => val1, “key2” => val2 }
- scope
- Enter a new scope. Returns a guard that times and manages indentation. Usage: let _scope = scope!(“my_scope”);
- scoped_
info - Log entering and exiting a scope at INFO level, with timing. Usage: let _scope = scoped_info!(“my_scope”);
- set_
context - Set a key-value pair in the current context.
- source_
location - Helper to extract source location (file, line, column)
- success
- Logs a message at the SUCCESS level.
- trace
- Logs a message at the TRACE level.
- try_log
- Try to log an error if Result is Err or Option is None, then return the value.
- warn
- Logs a message at the WARNING level.
Structs§
- Async
Logger Builder - Builder for the async logger
- Async
Logger Handle - Handle to the async logger
- LogRecord
- The “payload” of a log message.
- Metadata
- Metadata about a log message.
Enums§
- Level
Filter - An enum representing the available verbosity level filters of the logger.
Statics§
- STATIC_
LEVEL - Compile-time static log level for filtering (can be overridden at build time)
Traits§
- Log
- A trait encapsulating the operations required of a logger.