Expand description
§Logfather
A simple, lightweight, and easy-to-use logging system. It allows for detailed log messages, configurable output levels, and supports both file and terminal output.
§Features
- Easy to set up and use
- Supports logging to both the terminal and log files
- Customizable log message format
- Configurable log levels (Info, Debug, Warning, Error, Critical, and Diagnostic)
- Configurable level display including colors, highlights, and styles
- Optional result (prepend
r_) macros for managed errors - Thread-safe
§Getting Started
To start using Logfather, add the following to your Cargo.toml:
[dependencies]
logfather = "0.2.6"
- Check out [crates.io](https://crates.io/crates/logfather)- Minimum supported Rust version:
1.61.0
§Usage
Macros:
- Trace:
trace!()orr_trace!() - Debug:
debug!()orr_debug!() - Info:
info!()orr_info!() - Warning:
warn!(),warning!(),r_warn!(), orr_warning!() - Error:
error!()orr_error!() - Critical:
critical!(),crit!(),r_critical!(), orr_crit!() - Diagnostic:
diagnostic!(),diag!(),r_diagnostic!(), orr_diag!()
Quick setup for outputting to terminal:
use logfather::*;
let mut logger = Logger::new(); //Terminal output is enabled by default
error!("This is an error message");Setting up for only file output with specific error levels to be written:
use logfather::*;
let mut logger = Logger::new();
logger.terminal(false); // Disable terminal output
logger.file(true); // Enable file output
logger.path("log.txt"); // Set the path for file logging
logger.level(Level::Error); // Set the minimum level
info!("This is an info message"); // Will not be written to file
debug!("This is a debug message"); // Will not be written to file
warning!("This is a warning message"); // Will not be written to file
error!("This is an error message"); // Will be written to file
critical!("This is a critical message"); // Will be written to fileSet up for both terminal and file output capturing every level except warning
use logfather::*;
// Supports the builder pattern
let mut logger = Logger::new() // Terminal output is enabled by default
.file(true) // Enable file output
.path("log.txt") // Set the path for file logging
.ignore(Level::Warning); // Set the specific level to ignore
debug!("This is a debug message");
warning!("This is a warning message"); // Will be ignored
critical!("This is a critical message");Handle erroneous values gracefully with the r_ prepended macros
use logfather::*;
let mut logger = Logger::new();
match r_info!("This will return a Result<(), LogfatherError>") {
Ok(_) => println!("Successfully logged output"),
Err(e) => println!("Error logging output: {e}"),
}Debug and Diagnostic levels are Debug build only and will not be compiled in release builds
use logfather::*;
debug!("This is a debug message");
diag!("This is a diagnostic message");
diagnostic!("This will not output for release builds");Re-exports§
pub use logger::Logger;pub use logger::Level;pub use logger::TimeZone;pub use error::LogfatherError;pub use error::LogfatherResult;pub use logger::log;pub use logger::result_log;
Modules§
Macros§
- crit
- Logs a critical message.
- critical
- Logs a critical message.
- debug
- Logs a message for debugging and will be ignored on release builds.
- diag
- Logs a diagnostic message and ignores filters – debug builds only.
- diagnostic
- Logs a diagnostic message and ignores filters – debug builds only.
- error
- Logs an error message.
- info
- Logs an informational message.
- r_crit
- Logs a critical message.
- r_
critical - Logs a critical message.
- r_debug
- Logs a message for debugging and will be ignored on release builds.
- r_diag
- Logs a diagnostic message and ignores filters – debug builds only.
- r_
diagnostic - Logs a diagnostic message and ignores filters – debug builds only.
- r_error
- Logs an error message.
- r_info
- Logs an informational message.
- r_trace
- Logs a message for tracing - very low priority.
- r_warn
- Logs a warning message.
- r_
warning - Logs a warning message.
- trace
- Logs a message for tracing - very low priority.
- warn
- Logs a warning message.
- warning
- Logs a warning message.
Enums§
- Style
- Represents styling options for text display in the terminal, primarily intended to be used in tandem with the
dekor!()macro.