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"
dependencies = [
"dotenv",
"log",
"pretty_env_logger",
"reqwest",
"serde",

View file

@ -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"] }

View file

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

View file

@ -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";

View file

@ -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),
}
}

View file

@ -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),
}
}