Skip to content

Commit

Permalink
Logging system, Test
Browse files Browse the repository at this point in the history
I know there is probably a crate for this. Whatever.
  • Loading branch information
mutexdeveloper committed Jan 28, 2023
1 parent 80d6bbf commit 3e50e03
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Expand Up @@ -20,6 +20,9 @@ image = { version = "0.24.5" }
anyhow = { version = "1.0.68" }
tokio = { version = "1.24.2", features = ["full"] }
wry = { version = "0.24.1", features = ["devtools"] }
colored = { version = "2.0.0" }
strum_macros = { version = "0.24.3" }
strum = { version = "0.24.1" }

[profile.dev]
debug = true
Expand Down
40 changes: 40 additions & 0 deletions src/log.rs
@@ -0,0 +1,40 @@
use colored::Colorize;
use strum_macros::EnumIter;

/// Log writing priority
///
/// High: RED
///
/// Medium: Bright yellow
///
/// Low: Fading yellow
///
/// Info: Purple
#[derive(EnumIter, Debug)]
pub enum Priority {
High,
Medium,
Low,
Info

}
/// Write to log ( stdout )
pub fn write(message: String, priority: Priority) {
match priority {
Priority::High => {
println!("[ERROR]: {}\n", message.red())
}

Priority::Medium => {
println!("[ERROR]: {}\n", message.truecolor(255, 255, 0))
}

Priority::Low => {
println!("[ERROR]: {}\n", message.truecolor(177, 177, 0) )
}

Priority::Info => {
println!("[LOG]: {}\n", message.truecolor(170, 62, 255))
}
}
}
21 changes: 18 additions & 3 deletions src/main.rs
Expand Up @@ -7,6 +7,8 @@ extern crate tracing;

use tracing::error;

mod log;

use wry::{
application::{
event::{Event, StartCause, WindowEvent},
Expand Down Expand Up @@ -37,19 +39,17 @@ enum UserEvents {
CloseWindow,
}


// Convenient type alias of ``anyhow::Result`` type with ``wry::Error`` for LemonCord.
pub type Result<T> = anyhow::Result<T, wry::Error>;


pub const DISCORD: &str = "https://discord.com/app";
pub const APP_NAME: &str = "LemonCord";


#[tokio::main(flavor = "current_thread")]
async fn main() {
const VERSION: &str = env!("CARGO_PKG_VERSION");
println!("LemonCord : {:?}", &VERSION.to_string().to_owned());
log::write(format!("LemonCord : {:?}", &VERSION.to_string().to_owned()), log::Priority::Info);

if let Err(err) = discord().await {
error!("Fatal error in main: {err:?}");
Expand Down Expand Up @@ -261,3 +261,18 @@ fn load_icon(path: &std::path::Path) -> Icon {
};
Icon::from_rgba(icon_rgba, icon_width, icon_height).expect("Failed to open icon.")
}

// TESTS ( Move to new file maybe? )
#[cfg(test)]
mod tests {
use super::log;
use strum::IntoEnumIterator;

#[test]
fn test_log() {
for priority in log::Priority::iter() {
println!("{:?}", priority);
log::write("test_log: test logging capability".to_string(), priority);
}
}
}

0 comments on commit 3e50e03

Please sign in to comment.