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

§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");

Re-exports§

pub use config::LoggerConfig;
pub use config::LoggerConfigBuilder;
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;

Modules§

config
formatter
handler
level
logger
record

Macros§

critical
Logs a message at the CRITICAL level.
debug
Logs a message at the DEBUG level.
error
Logs a message at the ERROR level.
info
Logs a message at the INFO level.
log_with_metadata
Logs a message with metadata at the specified level.
success
Logs a message at the SUCCESS level.
trace
Logs a message at the TRACE level.
warn
Logs a message at the WARNING level.