# prettylog-rs [![Crates.io](https://img.shields.io/crates/v/prettylog-rs.svg)](https://crates.io/crates/prettylog-rs) A Rust logging library focused on readability in console. prettylog-rs takes advantage of ANSI color codes to make your logs look ✨ ***pretty*** ✨. ## Installation Add this to your `Cargo.toml`: ```toml [dependencies] prettylog-rs = "0.1.1" ``` ## Logging Logging is very easy, just call the `log(message, type)` function. The `type` parameter is optional and defaults to `LogType::Runtime`. ```rust use prettylog_rs::{log, LogType}; fn main() { prettylog_rs::logger::init(); log("Hello there!", LogType::Information); log("general kenobi", LogType::Network); } ``` You can also log exceptions! ```rust use std::error::Error; fn main() -> Result<(), Box> { prettylog_rs::logger::init(); // Some code that might throw an error let result = std::fs::read_to_string("non_existent_file.txt"); if let Err(e) = result { log_exception(&e); } Ok(()) } ``` ## Logger Settings You can change settings by modifying the `LoggerSettings`: ```rust use prettylog_rs::logger::{LoggerSettings, LoggerStyle}; fn main() { let mut settings = LoggerSettings::get(); settings.save_to_file = true; settings.save_directory_path = String::from("./logs/"); settings.log_file_name_format = String::from("%Y-%m-%d-%H%M%S"); settings.logger_style = LoggerStyle::Prefix; } ``` ## Log Types There are 16 default log types: **Debug**, **Information**, **Runtime**, **Network**, **Success**, **Warning**, **Error**, **Exception**, **Critical**, **Audit**, **Trace**, **Security**, **User Action**, **Performance**, **Config**, and **Fatal**. ### Custom log Types You can create custom log types by implementing your own enum and associated functions: ```rust use prettylog_rs::types::{AnsiColor, AnsiPair, CustomLogType, LogType}; pub enum MyCustomLogType { Cute, Git, FireWarning, } impl CustomLogType for MyCustomLogType { fn name(&self) -> &'static str { match self { MyCustomLogType::Cute => "≽^•⩊•^≼", MyCustomLogType::Git => "🤖 Git", MyCustomLogType::FireWarning => "🔥 Fire Warning", } } fn color_pair(&self) -> AnsiPair { match self { MyCustomLogType::Cute => AnsiPair::new(AnsiColor::CutePinkBackground, AnsiColor::CutePink), MyCustomLogType::Git => AnsiPair::new(AnsiColor::AquaBackground, AnsiColor::Aqua), MyCustomLogType::FireWarning => AnsiPair::new(AnsiColor::OrangeBackground, AnsiColor::Orange), } } } fn main() { prettylog_rs::logger::init(); log("T-This is vewy cuwute message OwO", LogType::Custom(&MyCustomLogType::Cute)); log("Refusing to merge unrelated histories", LogType::Custom(&MyCustomLogType::Git)); log("SERVER ROOM ON FIRE, DON'T LET ASO RUN WHILE LOOPS EVER AGAIN", LogType::Custom(&MyCustomLogType::FireWarning)); } ``` ## License This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. ## Contributing Contributions are welcome! Please feel free to submit a Pull Request. ## Credits https://github.com/LukynkaCZE https://github.com/LukynkaCZE/PrettyLog