Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ethereumdegen/degen-logger
Decent console logging in rust
https://github.com/ethereumdegen/degen-logger
Last synced: 15 days ago
JSON representation
Decent console logging in rust
- Host: GitHub
- URL: https://github.com/ethereumdegen/degen-logger
- Owner: ethereumdegen
- Created: 2023-07-24T04:05:08.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-07-24T04:55:38.000Z (over 1 year ago)
- Last Synced: 2024-04-25T13:22:20.370Z (7 months ago)
- Language: Rust
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Degen Logger
Logging utility for rust console
```
cargo add degen-logger
```## Overview
Sick and tired of constantly editing your println!() statements in your code? Degen Logger is here to save you. Simply define a custom enum in your code like this (probably off in some library/util folder) :
```
enum CustomLogStyle {
Warn,
Error,
Hidden
}impl degen_logger::DegenLogStyle for CustomLogStyle {
fn bold(&self) -> bool {
match self {
Self::Warn => true ,
Self::Error => false ,
Self::Hidden => false
}
}
fn show(&self) -> bool {
match self {
Self::Warn => true ,
Self::Error => true ,
Self::Hidden => false
}
}
fn get_log_color( &self ) -> degen_logger::LogColor {
match self {
Self::Warn => degen_logger::LogColor::Blue ,
Self::Error => degen_logger::LogColor::Red ,
Self::Hidden => degen_logger::LogColor::Black
}
}
}```
Then, in your code, log with that style like so:
```
degen_logger::log( format!("Listening on: {}", "localhost".to_string()), CustomLogStyle::Warn );
```Now all of your log statements have a CustomLogStyle. You can edit the implemented functions of this style in order to show/hide the messages of that style, change their print color, and determine boldness.
### Example usage
See main.rs