add basic logging

This commit is contained in:
notohh 2024-06-16 08:45:57 -04:00
parent 260c3e66a2
commit 307c502ac0
Signed by: notohh
GPG key ID: BD47506D475EE86D
6 changed files with 19 additions and 6 deletions

1
Cargo.lock generated
View file

@ -87,6 +87,7 @@ name = "botoh"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"dotenv", "dotenv",
"log",
"pretty_env_logger", "pretty_env_logger",
"reqwest", "reqwest",
"serde", "serde",

View file

@ -5,6 +5,7 @@ edition = "2021"
[dependencies] [dependencies]
dotenv = "0.15.0" dotenv = "0.15.0"
log = "0.4.21"
pretty_env_logger = "0.5.0" pretty_env_logger = "0.5.0"
reqwest = { version = "0.12.4", features = ["json"] } reqwest = { version = "0.12.4", features = ["json"] }
serde = { version = "1.0.203", features = ["derive"] } serde = { version = "1.0.203", features = ["derive"] }

View file

@ -73,6 +73,7 @@
]) ])
]; ];
RUST_BACKTRACE = 1; RUST_BACKTRACE = 1;
RUST_LOG = "info";
RUST_SRC_PATH = "${fenix.packages.${system}.complete.rust-src}/lib/rustlib/src/rust/library"; RUST_SRC_PATH = "${fenix.packages.${system}.complete.rust-src}/lib/rustlib/src/rust/library";
}; };
}); });

View file

@ -19,7 +19,10 @@ in {
type = types.package; type = types.package;
inherit (self.packages.${system}) default; inherit (self.packages.${system}) default;
}; };
log_level = mkOption {
type = types.str;
default = "info";
};
environmentFiles = mkOption { environmentFiles = mkOption {
type = types.listOf types.path; type = types.listOf types.path;
default = []; default = [];
@ -33,6 +36,9 @@ in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
systemd.services.botoh = { systemd.services.botoh = {
wantedBy = ["multi-user.target"]; wantedBy = ["multi-user.target"];
environment = {
RUST_LOG = cfg.log_level;
};
serviceConfig = { serviceConfig = {
EnvironmentFile = cfg.environmentFiles; EnvironmentFile = cfg.environmentFiles;
ExecStart = "${cfg.package}/bin/botoh"; ExecStart = "${cfg.package}/bin/botoh";

View file

@ -108,9 +108,9 @@ pub async fn lastfm_command(m: &PrivmsgMessage, c: &TwitchClient) {
Err(e) => eprintln!("{}", e), Err(e) => eprintln!("{}", e),
} }
} else { } 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),
} }
} }

View file

@ -8,20 +8,24 @@ use twitch_irc::message::ServerMessage;
mod client; mod client;
mod commands; mod commands;
#[macro_use]
extern crate log;
extern crate pretty_env_logger;
#[tokio::main] #[tokio::main]
pub async fn main() { pub async fn main() {
pretty_env_logger::try_init().expect("Failed to load logger");
let mut initial_channels = HashMap::new(); let mut initial_channels = HashMap::new();
let mut client = client(); let mut client = client();
initial_channels.insert("notnotoh", ()); initial_channels.insert("notnotoh", ());
initial_channels.insert("notohh", ()); initial_channels.insert("notohh", ());
initial_channels.insert("daph", ());
for (channels, _) in initial_channels.iter() { for (channels, _) in initial_channels.iter() {
match client.twitch_client.join(channels.to_owned().to_string()) { match client.twitch_client.join(channels.to_owned().to_string()) {
Ok(_) => println!("Joined channel {}", channels), Ok(_) => info!("Joined channel {}", channels),
Err(e) => eprintln!("Failed to join channels! {}", e), Err(e) => error!("Failed to join channels! {}", e),
} }
} }