diff --git a/Cargo.lock b/Cargo.lock index e102cab..7c34918 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -87,6 +87,7 @@ name = "botoh" version = "0.1.0" dependencies = [ "dotenv", + "log", "pretty_env_logger", "reqwest", "serde", diff --git a/Cargo.toml b/Cargo.toml index 4b66e1e..4cb1993 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] dotenv = "0.15.0" +log = "0.4.21" pretty_env_logger = "0.5.0" reqwest = { version = "0.12.4", features = ["json"] } serde = { version = "1.0.203", features = ["derive"] } diff --git a/flake.nix b/flake.nix index ad94d5d..c178dd5 100644 --- a/flake.nix +++ b/flake.nix @@ -73,6 +73,7 @@ ]) ]; RUST_BACKTRACE = 1; + RUST_LOG = "info"; RUST_SRC_PATH = "${fenix.packages.${system}.complete.rust-src}/lib/rustlib/src/rust/library"; }; }); diff --git a/nix/module.nix b/nix/module.nix index 4fa7646..7c5887f 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -19,7 +19,10 @@ in { type = types.package; inherit (self.packages.${system}) default; }; - + log_level = mkOption { + type = types.str; + default = "info"; + }; environmentFiles = mkOption { type = types.listOf types.path; default = []; @@ -33,6 +36,9 @@ in { config = mkIf cfg.enable { systemd.services.botoh = { wantedBy = ["multi-user.target"]; + environment = { + RUST_LOG = cfg.log_level; + }; serviceConfig = { EnvironmentFile = cfg.environmentFiles; ExecStart = "${cfg.package}/bin/botoh"; diff --git a/src/commands/lastfm.rs b/src/commands/lastfm.rs index c224471..9f11464 100644 --- a/src/commands/lastfm.rs +++ b/src/commands/lastfm.rs @@ -108,9 +108,9 @@ pub async fn lastfm_command(m: &PrivmsgMessage, c: &TwitchClient) { Err(e) => eprintln!("{}", e), } } else { - println!("Response error: {}", response.status()); + error!("Response error: {}", response.status()); } } - Err(e) => eprintln!("Error sending request: {}", e), + Err(e) => error!("Error sending request: {}", e), } } diff --git a/src/main.rs b/src/main.rs index 188412e..2414d77 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,20 +8,24 @@ use twitch_irc::message::ServerMessage; mod client; mod commands; +#[macro_use] +extern crate log; +extern crate pretty_env_logger; + #[tokio::main] pub async fn main() { + pretty_env_logger::try_init().expect("Failed to load logger"); let mut initial_channels = HashMap::new(); let mut client = client(); initial_channels.insert("notnotoh", ()); initial_channels.insert("notohh", ()); - initial_channels.insert("daph", ()); for (channels, _) in initial_channels.iter() { match client.twitch_client.join(channels.to_owned().to_string()) { - Ok(_) => println!("Joined channel {}", channels), - Err(e) => eprintln!("Failed to join channels! {}", e), + Ok(_) => info!("Joined channel {}", channels), + Err(e) => error!("Failed to join channels! {}", e), } }