Skip to content

Commit

Permalink
Use tracing instead of log
Browse files Browse the repository at this point in the history
  • Loading branch information
kasugamirai committed Jul 12, 2024
1 parent c1e8dd2 commit 8b4d3e9
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 139 deletions.
198 changes: 69 additions & 129 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ tokio = { version = "1", features = ["full"] }
serenity = "0.12.0"
async-trait = "0.1.77"
futures = "0.3.30"
log = "0.4.20"
dotenv = "0.15"
env_logger = "0.11.2"
config = "0.14.0"
url = "2.5.0"
reqwest = "0.12.2"
thiserror = "1.0.0"
tracing = "0.1.37"
tracing-subscriber = "0.3.16"
10 changes: 5 additions & 5 deletions src/bin/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use serenity::all::GatewayIntents;
use serenity::Client;
use std::env;
use std::path::Path;
use tracing::{error, info};

#[tokio::main]
async fn main() {
// Initialize the logger

env_logger::init();
// Initialize the logger with tracing
tracing_subscriber::fmt::init();

// Load environment variables
load_environment_variables();
Expand Down Expand Up @@ -37,9 +37,9 @@ async fn main() {
.await;

// Start listening for events
println!("Bot is now running. Press Ctrl+C to stop.");
info!("Bot is now running. Press Ctrl+C to stop.");
if let Err(why) = client.start().await {
log::error!("Client error: {:?}", why);
error!("Client error: {:?}", why);
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/discord/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use serenity::model::channel::Message;
use std::time::Duration;
use thiserror::Error;
use tokio::time::interval;
use tracing::error;

#[derive(Debug, Error)]
pub enum Error {
Expand Down Expand Up @@ -52,15 +53,15 @@ impl EventHandler for Handler {
let mut stream = match self.gpt_client.send_message_streaming(prompt).await {
Ok(stream) => stream,
Err(e) => {
log::error!("Error sending message to ChatGPT: {:?}", e);
error!("Error sending message to ChatGPT: {:?}", e);
return;
}
};

let processing_message = match msg.channel_id.say(&ctx.http, "Processing...").await {
Ok(message) => message,
Err(why) => {
log::error!("Error sending message: {:?}", why);
error!("Error sending message: {:?}", why);
return;
}
};
Expand All @@ -84,7 +85,7 @@ impl EventHandler for Handler {
if !result.is_empty() {
let edit = EditMessage::default().content(&result);
if let Err(why) = msg.channel_id.edit_message(&ctx.http, processing_message.id, edit).await {
log::error!("Error editing message: {:?}", why);
error!("Error editing message: {:?}", why);
}
}
}
Expand Down

0 comments on commit 8b4d3e9

Please sign in to comment.