| Crates.io | loggit |
| lib.rs | loggit |
| version | 0.1.9 |
| created_at | 2025-03-16 13:57:01.517417+00 |
| updated_at | 2025-06-24 12:38:56.885179+00 |
| description | Loggit is a lightweight, easy-to-use logging library for Rust. |
| homepage | https://github.com/DobbiKov/loggit |
| repository | https://github.com/DobbiKov/loggit |
| max_upload_size | |
| id | 1594434 |
| size | 377,971 |
Loggit is a lightweight, easy-to-use logging library for Rust. It provides ready-to-use logger macros that let you start logging with zero boilerplate. You simply import and use it; no additional setup is required for basic usage. However, if you need more control, you can customize the logging format, colors, and minimum logging level.
trace!, debug!, info!, warn!, and error!.{level}, {file}, {line}, and {message}.env or default files without any code!Add LogGit to your Cargo.toml:
[dependencies]
loggit = "0.1.9"
or just write in the terminal:
cargo add loggit
Simply import the logger macros and use it in your project:
use loggit::{trace, debug, info, warn, error};
fn main() {
trace!("This is a trace message.");
debug!("Debug message: variable value = {}", 42);
info!("Informational message.");
warn!("Warning: something might be off.");
error!("Error occurred: {}", "example error");
}

Set the minimum log level so that only messages at that level and above are printed:
use loggit::logger::set_log_level;
use loggit::Level;
fn main() {
// Set log level to DEBUG; TRACE messages will be ignored.
set_log_level(Level::DEBUG);
debug!("This is a debug message.");
trace!("This trace message will not be logged.");
}

You can adjust the log format globally or per log level. Templates can include placeholders like {level}, {file}, {line}, and {message}. Colors can be configured by wrapping text with color tags.
Global Format Customization
use loggit::logger::set_global_formatting;
fn main() {
// Set a global custom log format using color tags.
set_global_formatting("<green>[{level}]<green> ({file}:{line}) - {message}");
info!("This info message follows the new global format.");
error!("The error message as well.");
}

Level-Specific Format Customization
use loggit::logger::set_level_formatting;
use loggit::Level;
fn main() {
// Customize the ERROR log format specifically.
set_level_formatting(
Level::ERROR,
"<red>[{level}]<red> <blue>({file}:{line})<blue> - <red>{message}<red>"
);
info!("Info follows the standard formatting");
info!("Warn follows the standard formatting");
error!("This error message will follow the custom error format.");
}

Enable or disable colored output based on your preference:
use loggit::logger::set_colorized;
fn main() {
// Enable colored output.
set_colorized(false);
info!("This info message will not be colorized");
}

Control whether messages are printed directly to the terminal:
use loggit::logger::set_print_to_terminal;
fn main() {
// Disable terminal output (for example, if you want to log to a file instead).
set_print_to_terminal(false);
info!("This message will not be printed to the terminal.");
}

Enable save all your logs to a file
use loggit::logger::set_file;
fn main() {
// provide file name
set_file("file_name.txt");
}
You can choose a format for the file name:
use loggit::logger::set_file;
fn main() {
// provide file name
set_file("{level}-log-on-{date}.txt");
}

Choose how oftenly you change your file
use loggit::logger::{set_file, add_rotation};
fn main() {
// provide file name
set_file("{level}-log-on-{date}.txt");
add_rotation("1 week"); // change the file every week
add_rotation("5 MB"); // max file size 5 MB, then again change of the file
}
Save your space by compressing log files
use loggit::logger::{set_file, set_compression};
fn main() {
// provide file name
set_file("{level}-log-on-{date}.txt");
set_compression("zip");
}
Choose the directory to save archived log files to
use loggit::logger::{set_file, set_compression, set_archive_dir};
fn main() {
// provide file name
set_file("{level}-log-on-{date}.txt");
set_compression("zip");
set_archive_dir("my_archives"); // all the archives will be stored in the `my_archives` directory
}
colorized=false file_name="save_here.txt" cargo run
use loggit::logger::{load_config_from_file};
fn main(){
let _ = load_config_from_file("my_conf.json");
}
Or simply crate a config file with one of those names:
loggit.envloggit.iniloggit.jsonAnd it will be loaded automatically
A complete user documentation can be found here
Internally, LogGit uses a simple configuration structure which holds:
The default configuration already provides sensible defaults, so you can get started right away. Customization is available for those who need advanced logging setups.
Contributions and suggestions are welcome! Feel free to open issues or submit pull requests to help improve LogGit.
There are two types of tests:
src/tests/ folder.tests/ folder.Using cargo test is not recommended as it runs tests using multiple threads that doesn't respect the library logic, thus the next scripts are recommended:
test.sh for unit testsint_test.sh for integration testsIn order to read release notes for each version, click here
LogGit is licensed under the MIT License.