9 releases

new 0.2.6 Apr 24, 2024
0.2.5 Mar 29, 2024
0.2.4 Feb 8, 2024
0.2.3 Jan 8, 2024
0.1.1 Jan 6, 2024

#193 in Debugging

Download history 2/week @ 2023-12-31 32/week @ 2024-01-07 2/week @ 2024-01-21 23/week @ 2024-02-04 6/week @ 2024-02-18 11/week @ 2024-02-25 5/week @ 2024-03-10 13/week @ 2024-03-17 161/week @ 2024-03-24 45/week @ 2024-03-31 18/week @ 2024-04-07 4/week @ 2024-04-14

229 downloads per month

MIT license

50KB
548 lines

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"
  • Minimum supported Rust version: 1.61.0
  • Check out crates.io
  • All the information you'll need in the Documentation

Usage

Macros:

  • Trace: trace!() or r_trace!()
  • Debug: debug!() or r_debug!()
  • Info: info!() or r_info!()
  • Warning: warn!(), warning!(), r_warn!(), or r_warning!()
  • Error: error!() or r_error!()
  • Critical: critical!(), crit!(), r_critical!(), or r_crit!()
  • Diagnostic: diagnostic!(), diag!(), r_diagnostic!(), or r_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 file

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

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

._. why would you do this?

  • Please open an issue with [FEATURE REQUEST] in the title if you wish to
  • If you wish to contribute, issues and feature requests are a great way to do so. If you wish to fork and open a PR with changes, please provide information on what is being changed in great detail. This is my own pet project, so I will be opinionated, but I'm not against improvements or suggestions for improvements.

Dependencies

~1MB
~18K SLoC