Crate rust_loguru

Source
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§

AsyncLoggerBuilder
Builder for the async logger
AsyncLoggerHandle
Handle to the async logger
LogRecord
The “payload” of a log message.
Metadata
Metadata about a log message.

Enums§

LevelFilter
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.