Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: switch to tracing #223

Merged
merged 4 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 20 additions & 33 deletions Cargo.lock

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

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ repository = "https://github.com/serenity-rs/poise/"

[dependencies]
tokio = { version = "1.25.1", default-features = false } # for async in general
futures-core = { version = "0.3.13", default-features = false } # for async in general
futures-util = { version = "0.3.13", default-features = false } # for async in general
once_cell = { version = "1.7.2", default-features = false, features = ["std"] } # to store and set user data
poise_macros = { path = "macros", version = "0.5.7" } # remember to update the version on changes!
async-trait = { version = "0.1.48", default-features = false } # various traits
regex = { version = "1.6.0", default-features = false, features = ["std"] } # prefix
log = { version = "0.4.14", default-features = false } # warning about weird state
tracing = { version = "0.1.40", features = ["log"] }
vidhanio marked this conversation as resolved.
Show resolved Hide resolved
derivative = "2.2.0"
parking_lot = "0.12.1"

Expand All @@ -29,7 +28,7 @@ version = "0.11.5"
# For the examples
tokio = { version = "1.25.1", features = ["rt-multi-thread"] }
futures = { version = "0.3.13", default-features = false }
env_logger = "0.10.0"
env_logger = "0.3.29"
vidhanio marked this conversation as resolved.
Show resolved Hide resolved
fluent = "0.16.0"
intl-memoizer = "0.5.1"
fluent-syntax = "0.11"
Expand Down
2 changes: 1 addition & 1 deletion examples/fluent_localization/translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub fn get(
.or_else(|| format(&translations.main, id, attr, args))
// If this message ID is not present in any translation files whatsoever
.unwrap_or_else(|| {
log::warn!("unknown fluent message identifier `{}`", id);
tracing::warn!("unknown fluent message identifier `{}`", id);
id.to_string()
})
}
Expand Down
19 changes: 10 additions & 9 deletions src/builtins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ pub use paginate::*;

use crate::serenity_prelude as serenity;

/// An error handler that logs errors either via the [`log`] crate or via a Discord message. Set
/// up a logger (e.g. `env_logger::init()`) to see the logged errors from this method.
/// An error handler that logs errors either via the [`tracing`] crate or via a Discord message. Set
/// up a logger (e.g. `env_logger::init()`) or a tracing subscriber
/// (e.g. `tracing_subscriber::fmt::init()`) to see the logged errors from this method.
///
/// If the user invoked the command wrong ([`crate::FrameworkError::ArgumentParse`]), the command
/// help is displayed and the user is directed to the help menu.
Expand All @@ -27,7 +28,7 @@ use crate::serenity_prelude as serenity;
/// ```rust,no_run
/// # async { let error: poise::FrameworkError<'_, (), &str> = todo!();
/// if let Err(e) = poise::builtins::on_error(error).await {
/// log::error!("Fatal error while sending error message: {}", e);
/// tracing::error!("Fatal error while sending error message: {}", e);
/// }
/// # };
/// ```
Expand All @@ -38,7 +39,7 @@ pub async fn on_error<U, E: std::fmt::Display + std::fmt::Debug>(
crate::FrameworkError::Setup { error, .. } => {
eprintln!("Error in user data setup: {}", error);
}
crate::FrameworkError::EventHandler { error, event, .. } => log::error!(
crate::FrameworkError::EventHandler { error, event, .. } => tracing::error!(
"User event event handler encountered an error on {} event: {}",
event.name(),
error
Expand Down Expand Up @@ -91,14 +92,14 @@ pub async fn on_error<U, E: std::fmt::Display + std::fmt::Debug>(
ctx.say(response).await?;
}
crate::FrameworkError::CommandStructureMismatch { ctx, description } => {
log::error!(
tracing::error!(
"Error: failed to deserialize interaction arguments for `/{}`: {}",
ctx.command.name,
description,
);
}
crate::FrameworkError::CommandCheckFailed { ctx, error } => {
log::error!(
tracing::error!(
"A command check failed in command {} for user {}: {:?}",
ctx.command().name,
ctx.author().name,
Expand Down Expand Up @@ -162,7 +163,7 @@ pub async fn on_error<U, E: std::fmt::Display + std::fmt::Debug>(
ctx.send(|b| b.content(response).ephemeral(true)).await?;
}
crate::FrameworkError::DynamicPrefix { error, msg, .. } => {
log::error!(
tracing::error!(
"Dynamic prefix failed for message {:?}: {}",
msg.content,
error
Expand All @@ -173,14 +174,14 @@ pub async fn on_error<U, E: std::fmt::Display + std::fmt::Debug>(
prefix,
..
} => {
log::warn!(
tracing::warn!(
"Recognized prefix `{}`, but didn't recognize command name in `{}`",
prefix,
msg_content,
);
}
crate::FrameworkError::UnknownInteraction { interaction, .. } => {
log::warn!(
tracing::warn!(
"received unknown interaction \"{}\"",
interaction.data().name
);
Expand Down
2 changes: 1 addition & 1 deletion src/builtins/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ pub async fn register_application_commands_buttons<U, E>(
"register.guild" => (true, false),
"unregister.guild" => (false, false),
other => {
log::warn!("unknown register button ID: {:?}", other);
tracing::warn!("unknown register button ID: {:?}", other);
return Ok(());
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/dispatch/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async fn user_permissions(
let channel = match channel_id.to_channel(ctx).await {
Ok(serenity::Channel::Guild(channel)) => channel,
Ok(_other_channel) => {
log::warn!(
tracing::warn!(
"guild message was supposedly sent in a non-guild channel. Denying invocation"
);
return None;
Expand Down Expand Up @@ -97,7 +97,7 @@ async fn check_permissions_and_cooldown_single<'a, U, E>(
let channel = match ctx.channel_id().to_channel(ctx.serenity_context()).await {
Ok(channel) => channel,
Err(e) => {
log::warn!("Error when getting channel: {}", e);
tracing::warn!("Error when getting channel: {}", e);

return Err(crate::FrameworkError::NsfwOnly { ctx });
}
Expand Down
2 changes: 1 addition & 1 deletion src/dispatch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub async fn dispatch_event<U: Send + Sync, E>(
.process_message_delete(*deleted_message_id);
if let Some(bot_response) = bot_response {
if let Err(e) = bot_response.delete(ctx).await {
log::warn!("failed to delete bot response: {}", e);
tracing::warn!("failed to delete bot response: {}", e);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/dispatch/slash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async fn run_command<U, E>(
}
}
other => {
log::warn!("unknown interaction command type: {:?}", other);
tracing::warn!("unknown interaction command type: {:?}", other);
return Ok(());
}
};
Expand Down Expand Up @@ -194,7 +194,7 @@ async fn run_autocomplete<U, E>(
let focused_option = match ctx.args.iter().find(|o| o.focused) {
Some(x) => x,
None => {
log::warn!("no option is focused in autocomplete interaction");
tracing::warn!("no option is focused in autocomplete interaction");
return Ok(());
}
};
Expand Down Expand Up @@ -232,15 +232,15 @@ async fn run_autocomplete<U, E>(
let autocomplete_response = match autocomplete_callback(ctx, partial_input).await {
Ok(x) => x,
Err(e) => {
log::warn!("couldn't generate autocomplete response: {}", e);
tracing::warn!("couldn't generate autocomplete response: {}", e);
return Ok(());
}
};

let interaction = match ctx.interaction {
crate::ApplicationCommandOrAutocompleteInteraction::Autocomplete(x) => x,
_ => {
log::warn!("a non-autocomplete interaction was given to run_autocomplete()");
tracing::warn!("a non-autocomplete interaction was given to run_autocomplete()");
return Ok(());
}
};
Expand All @@ -253,7 +253,7 @@ async fn run_autocomplete<U, E>(
})
.await
{
log::warn!("couldn't send autocomplete response: {}", e);
tracing::warn!("couldn't send autocomplete response: {}", e);
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/framework/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ and enable MESSAGE_CONTENT in your Discord bot dashboard
options.commands.extend(self.commands);
if self.initialize_owners {
if let Err(e) = super::insert_owners_from_http(&token, &mut options.owners).await {
log::warn!("Failed to insert owners from HTTP: {}", e);
tracing::warn!("Failed to insert owners from HTTP: {}", e);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ fn message_content_intent_sanity_check<U, E>(
|| prefix_options.stripped_dynamic_prefix.is_some();
let can_receive_message_content = intents.contains(serenity::GatewayIntents::MESSAGE_CONTENT);
if is_prefix_configured && !can_receive_message_content {
log::warn!("Warning: MESSAGE_CONTENT intent not set; prefix commands will not be received");
tracing::warn!(
"Warning: MESSAGE_CONTENT intent not set; prefix commands will not be received"
);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ pub fn find_modal_text(
let text = match row.components.get_mut(0) {
Some(serenity::ActionRowComponent::InputText(text)) => text,
Some(_) => {
log::warn!("unexpected non input text component in modal response");
tracing::warn!("unexpected non input text component in modal response");
continue;
}
None => {
log::warn!("empty action row in modal response");
tracing::warn!("empty action row in modal response");
continue;
}
};
Expand All @@ -30,7 +30,7 @@ pub fn find_modal_text(
return if value.is_empty() { None } else { Some(value) };
}
}
log::warn!(
tracing::warn!(
"{} not found in modal response (expected at least blank string)",
custom_id
);
Expand Down
2 changes: 1 addition & 1 deletion src/structs/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ context_methods! {
match self.framework().shard_manager.lock().await.runners.lock().await.get(&serenity::ShardId(self.serenity_context().shard_id)) {
Some(runner) => runner.latency.unwrap_or(std::time::Duration::ZERO),
None => {
log::error!("current shard is not in shard_manager.runners, this shouldn't happen");
tracing::error!("current shard is not in shard_manager.runners, this shouldn't happen");
std::time::Duration::ZERO
}
}
Expand Down
Loading