| Crates.io | lumelog |
| lib.rs | lumelog |
| version | 0.1.5 |
| created_at | 2024-12-07 19:04:46.344537+00 |
| updated_at | 2024-12-07 23:18:35.462575+00 |
| description | A lightweight, flexible, and configurable logging library for Rust, with support for runtime configuration and build-mode detection. |
| homepage | |
| repository | https://github.com/LinearDev/lumelog |
| max_upload_size | |
| id | 1475820 |
| size | 33,465 |
LumeLog is a lightweight, flexible, and configurable logging library for Rust. It supports different log levels, runtime configuration, and styled log outputs, making it suitable for both development and production environments.
ERROR, WARN, INFO, DEBUG, and TRACE.Add lumelog to your Cargo.toml:
[dependencies]
lumelog = "0.1.3"
Then, include it in your code:
use lumelog::{info, warn, error, ConfigBuilder, LogLevel};
Here’s a basic example to get started:
use lumelog::{info, error, warn, debug, ConfigBuilder, LogLevel};
fn main() {
// Configure LumeLog
let config = ConfigBuilder::new().build().unwrap();
// Example log messages
info!("This is an informational message");
warn!("This is a warning!");
error!("This is an error!");
//Example with variables
let test_var = "some data to test"
debug!("This is debug variable value: {}", test_var)
}
You can customize LumeLog using the ConfigBuilder. Here’s what you can configure:
Example:
let config = ConfigBuilder::new()
.log_level(Some(LogLevel::DEBUG)) // Log all messages down to DEBUG
.build()
.unwrap();
Enable file logging and specify a path and format:
use lumelog::{FileLoggerBuilder, FileLoggerFormat};
let config = ConfigBuilder::new()
.file_logger_config(Some(
FileLoggerBuilder::new()
.path("./app.log".to_string()) // Specify log file path
.log_format(FileLoggerFormat::TEXT) // Set file format to JSON
))
.build()
.unwrap();
LumeLog provides easy-to-use macros for logging messages at various levels:
Example:
info!("User {} has logged in", "Alice");
warn!("Memory usage is high: {}%", 90);
error!("Failed to save data: {}", "Disk full");
ConfigBuilder{
log_level: Some(lumelog::LogLevel::INFO), // Log level for the logger.
log_in_release: true, // Enables or disables logging in release mode.
log_with_time: Some(true), // Enables or disables time-stamping in logs.
std: true, // Enables or disables standard output logging.
file_logger_config: Some(FileLoggerBuilder{ // Configuration for file-based logging.,
enabled: true, // Enables or disables file-based logging.
path: Some("./my_app.log".to_string()), // Path to the log file.
log_format: Some(FileLoggerFormat::TEXT), // Format of the log file.
})
}
LumeLog automatically detects build mode (debug or release) and adjusts logging behavior accordingly. You can override this behavior using the log_in_release configuration.
!NOTE: If log_in_release is enabled, trace and debug messages will not be logged.
LumeLog is dual-licensed under the MIT or Apache 2.0 license. See LICENSE-MIT or LICENSE-APACHE for details.