diff --git a/Cargo.lock b/Cargo.lock index 83950ca..993d04d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -38,6 +38,15 @@ dependencies = [ "thiserror", ] +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + [[package]] name = "arrayvec" version = "0.4.12" @@ -129,17 +138,6 @@ dependencies = [ "tungstenite 0.16.0", ] -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - [[package]] name = "audiopus" version = "0.2.0" @@ -332,17 +330,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "colored" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd" -dependencies = [ - "atty", - "lazy_static", - "winapi", -] - [[package]] name = "command_attr" version = "0.3.8" @@ -476,6 +463,17 @@ dependencies = [ "num_cpus", ] +[[package]] +name = "dashmap" +version = "5.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c8858831f7781322e539ea39e72449c46b059638250c14344fec8d0aa6e539c" +dependencies = [ + "cfg-if 1.0.0", + "num_cpus", + "parking_lot 0.12.0", +] + [[package]] name = "derive_more" version = "0.99.17" @@ -603,15 +601,6 @@ dependencies = [ "instant", ] -[[package]] -name = "fern" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9a4820f0ccc8a7afd67c39a0f1a0f4b07ca1725164271a64939d7aeb9af065" -dependencies = [ - "log", -] - [[package]] name = "flate2" version = "1.0.22" @@ -1079,9 +1068,9 @@ checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" [[package]] name = "js-sys" -version = "0.3.56" +version = "0.3.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a38fc24e30fd564ce974c02bf1d337caddff65be6cc4735a1f7eab22a7440f04" +checksum = "671a26f820db17c2a2750743f1dd03bafd15b98c9f30c7c2628c024c05d73397" dependencies = [ "wasm-bindgen", ] @@ -1093,10 +1082,9 @@ source = "git+https://gitlab.com/vicky5124/lavalink-rs/?rev=2487c295#2487c2953c7 dependencies = [ "async-trait", "async-tungstenite 0.16.1", - "dashmap", + "dashmap 4.0.2", "futures", "http", - "log", "parking_lot 0.12.0", "regex", "reqwest", @@ -1107,6 +1095,7 @@ dependencies = [ "songbird", "tokio", "tokio-native-tls", + "tracing", "typemap_rev", "version_check", ] @@ -1119,9 +1108,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.121" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f" +checksum = "ec647867e2bf0772e28c8bcde4f0d19a9216916e890543b5a03ed8ef27b8f259" [[package]] name = "lock_api" @@ -1187,6 +1176,15 @@ dependencies = [ "xml5ever", ] +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata", +] + [[package]] name = "matches" version = "0.1.9" @@ -1838,6 +1836,15 @@ dependencies = [ "regex-syntax", ] +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax", +] + [[package]] name = "regex-syntax" version = "0.6.25" @@ -1892,7 +1899,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots 0.22.2", + "webpki-roots 0.22.3", "winreg", ] @@ -2256,16 +2263,17 @@ dependencies = [ [[package]] name = "serenity-rich-interaction" -version = "0.2.6" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9bc8919bb2b46d927f1810a47a030cfa62a720fe6ef33b68bbdbc39394fe001" +checksum = "b7468dce50adc3f39e3fc65606cfe660148958b36d1f54454b845cbf710de02b" dependencies = [ + "dashmap 5.2.0", "futures", - "log", "serde_json", "serenity", "thiserror", "tokio", + "tracing", ] [[package]] @@ -2304,6 +2312,15 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "sharded-slab" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +dependencies = [ + "lazy_static", +] + [[package]] name = "signal-hook-registry" version = "1.4.0" @@ -2351,7 +2368,7 @@ dependencies = [ "async-tungstenite 0.14.0", "audiopus", "byteorder", - "dashmap", + "dashmap 4.0.2", "discortp", "flume", "futures", @@ -2486,9 +2503,9 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.23.8" +version = "0.23.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad04c584871b8dceb769a20b94e26a357a870c999b7246dcd4cb233d927547e3" +checksum = "b3fb8adaa82317f1e8a040281807f411803c9111303cfe129b4abb4a14b2c223" dependencies = [ "cfg-if 1.0.0", "core-foundation-sys", @@ -2550,6 +2567,15 @@ dependencies = [ "syn", ] +[[package]] +name = "thread_local" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" +dependencies = [ + "once_cell", +] + [[package]] name = "time" version = "0.1.44" @@ -2587,13 +2613,10 @@ dependencies = [ "build-time", "chrono", "chrono-tz", - "colored", "dotenv", - "fern", "futures", "lavalink-rs", "lazy_static", - "log", "minecraft-data-rs", "rand 0.8.5", "regex", @@ -2609,6 +2632,8 @@ dependencies = [ "sysinfo", "thiserror", "tokio", + "tracing", + "tracing-subscriber", "trigram", "typemap_rev", "xkcd-search", @@ -2725,9 +2750,9 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.32" +version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a1bdf54a7c28a2bbf701e1d2233f6c77f473486b94bee4f9678da5a148dca7f" +checksum = "80b9fa4360528139bc96100c160b7ae879f5567f49f1782b0b02035b0358ebf3" dependencies = [ "cfg-if 1.0.0", "log", @@ -2754,6 +2779,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90442985ee2f57c9e1b548ee72ae842f4a9a20e3f417cc38dbc5dc684d9bb4ee" dependencies = [ "lazy_static", + "valuable", ] [[package]] @@ -2766,6 +2792,35 @@ dependencies = [ "tracing", ] +[[package]] +name = "tracing-log" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6923477a48e41c1951f1999ef8bb5a3023eb723ceadafe78ffb65dc366761e3" +dependencies = [ + "lazy_static", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bc28f93baff38037f64e6f43d34cfa1605f27a49c34e8a04c5e78b0babf2596" +dependencies = [ + "ansi_term", + "lazy_static", + "matchers", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + [[package]] name = "trigram" version = "0.4.4" @@ -2957,6 +3012,12 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4bf03e0ca70d626ecc4ba6b0763b934b6f2976e8c744088bb3c1d646fbb1ad0" +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "vcpkg" version = "0.2.15" @@ -2999,9 +3060,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.79" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25f1af7423d8588a3d840681122e72e6a24ddbcb3f0ec385cac0d12d24256c06" +checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -3009,9 +3070,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.79" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b21c0df030f5a177f3cba22e9bc4322695ec43e7257d865302900290bcdedca" +checksum = "53e04185bfa3a779273da532f5025e33398409573f348985af9a1cbf3774d3f4" dependencies = [ "bumpalo", "lazy_static", @@ -3024,9 +3085,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.29" +version = "0.4.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2eb6ec270a31b1d3c7e266b999739109abce8b6c87e4b31fcfcd788b65267395" +checksum = "6f741de44b75e14c35df886aff5f1eb73aa114fa5d4d00dcd37b5e01259bf3b2" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -3036,9 +3097,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.79" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f4203d69e40a52ee523b2529a773d5ffc1dc0071801c87b3d270b471b80ed01" +checksum = "17cae7ff784d7e83a2fe7611cfe766ecf034111b49deb850a3dc7699c08251f5" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3046,9 +3107,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.79" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa8a30d46208db204854cadbb5d4baf5fcf8071ba5bf48190c3e59937962ebc" +checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b" dependencies = [ "proc-macro2", "quote", @@ -3059,15 +3120,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.79" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d958d035c4438e28c70e4321a2911302f10135ce78a9c7834c0cab4123d06a2" +checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744" [[package]] name = "web-sys" -version = "0.3.56" +version = "0.3.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c060b319f29dd25724f09a2ba1418f142f539b2be99fbf4d2d5a8f7330afb8eb" +checksum = "7b17e741662c70c8bd24ac5c5b18de314a2c26c32bf8346ee1e6f53de919c283" dependencies = [ "js-sys", "wasm-bindgen", @@ -3113,9 +3174,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.22.2" +version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "552ceb903e957524388c4d3475725ff2c8b7960922063af6ce53c9a43da07449" +checksum = "44d8de8415c823c8abd270ad483c6feeac771fad964890779f9a8cb24fbbc1bf" dependencies = [ "webpki 0.22.0", ] diff --git a/Cargo.toml b/Cargo.toml index ff3d401..f83005c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,6 @@ panic = 'abort' [dependencies] bot-database = {path="./bot-database"} bot-coreutils = {path="./bot-coreutils"} -serenity-rich-interaction = "0.2.6" serenity = "0.10.10" dotenv = "0.15.0" serde_derive = "1.0.136" @@ -29,10 +28,7 @@ regex = "1.5.5" aspotify = "0.7.1" lazy_static = "1.4.0" futures = "0.3.21" -log = "0.4.16" -fern = "0.6.0" chrono = "0.4.19" -colored = "2.0.0" sysinfo = "0.23.8" reqwest = "0.11.10" chrono-tz = "0.6.1" @@ -44,6 +40,11 @@ youtube-metadata = "0.2.0" xkcd-search = "0.1.2" animethemes-rs = "0.3.0" build-time = "0.1.1" +tracing-subscriber = {version = "0.3.10", features = ["env-filter"] } +tracing = "0.1.32" + +[dependencies.serenity-rich-interaction] +version = "0.3.0" [dependencies.tokio] version = "1.17.0" @@ -52,5 +53,5 @@ features = ["macros", "rt-multi-thread"] [dependencies.lavalink-rs] git = "https://gitlab.com/vicky5124/lavalink-rs/" rev = "2487c295" -features=["native", "serenity", "songbird", "normal-log"] +features=["native", "serenity", "songbird", "tracing-log"] default-features = false diff --git a/src/client.rs b/src/client.rs index 61a5c7d..240498f 100644 --- a/src/client.rs +++ b/src/client.rs @@ -102,7 +102,7 @@ async fn after_hook(ctx: &Context, msg: &Message, cmd_name: &str, error: Command m.embed(|e| e.title("Error occurred").description(format!("{}", why))) }) .await; - log::warn!("Error in {}: {:?}", cmd_name, why); + tracing::warn!("Error in {}: {:?}", cmd_name, why); } let database = get_database_from_context(ctx).await; let _ = database @@ -118,7 +118,7 @@ async fn after_hook(ctx: &Context, msg: &Message, cmd_name: &str, error: Command #[hook] async fn before_hook(ctx: &Context, msg: &Message, _: &str) -> bool { - log::trace!("Got command message {}", msg.content); + tracing::trace!("Got command message {}", msg.content); let _ = msg.channel_id.broadcast_typing(ctx).await; true } diff --git a/src/commands/minecraft/enchantment.rs b/src/commands/minecraft/enchantment.rs index 1b48997..ee7825b 100644 --- a/src/commands/minecraft/enchantment.rs +++ b/src/commands/minecraft/enchantment.rs @@ -16,7 +16,7 @@ pub(crate) async fn enchantment(ctx: &Context, msg: &Message, args: Args) -> Com let data = ctx.data.read().await; let store = data.get::().expect("Failed to get store"); let enchantment_name = args.message().to_lowercase(); - log::debug!("Searching for enchantment {}", enchantment_name); + tracing::debug!("Searching for enchantment {}", enchantment_name); let enchantments_by_name = store .minecraft_data_api @@ -29,7 +29,7 @@ pub(crate) async fn enchantment(ctx: &Context, msg: &Message, args: Args) -> Com enchantment_name )))? .clone(); - log::trace!("Enchantment is {:?}", enchantment); + tracing::trace!("Enchantment is {:?}", enchantment); msg.channel_id .send_message(ctx, |m| { diff --git a/src/commands/minecraft/item.rs b/src/commands/minecraft/item.rs index a8cc563..208cfeb 100644 --- a/src/commands/minecraft/item.rs +++ b/src/commands/minecraft/item.rs @@ -19,9 +19,9 @@ pub(crate) async fn item(ctx: &Context, msg: &Message, args: Args) -> CommandRes let store = data.get::().expect("Failed to get store"); let item_name = args.message().to_lowercase(); - log::debug!("Searching for item '{}'", item_name); + tracing::debug!("Searching for item '{}'", item_name); let information = get_item_full_information(&item_name, &store.minecraft_data_api)?; - log::trace!("Item full information is {:?}", information); + tracing::trace!("Item full information is {:?}", information); create_item_message(ctx, msg.channel_id, information).await?; handle_autodelete(ctx, msg).await?; diff --git a/src/commands/misc/clear.rs b/src/commands/misc/clear.rs index 2d174fa..2399210 100644 --- a/src/commands/misc/clear.rs +++ b/src/commands/misc/clear.rs @@ -17,17 +17,17 @@ use serenity_rich_interaction::ephemeral_message::EphemeralMessage; #[required_permissions("MANAGE_MESSAGES")] async fn clear(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { let limit = args.single::().unwrap_or(20); - log::debug!("Deleting messages for channel {}", msg.channel_id); + tracing::debug!("Deleting messages for channel {}", msg.channel_id); let messages = msg.channel_id.messages(ctx, |b| b.limit(limit)).await?; - log::debug!("Deleting {} messages", messages.len()); + tracing::debug!("Deleting {} messages", messages.len()); let futures: Vec>> = messages .into_iter() .map(|m| async move { ctx.http.delete_message(m.channel_id.0, m.id.0).await }.boxed()) .collect(); - log::debug!("Waiting for all messages to be deleted"); + tracing::debug!("Waiting for all messages to be deleted"); let deleted = futures::future::join_all(futures).await; let deleted_count = deleted.into_iter().filter(|d| d.is_ok()).count(); - log::debug!("{} Messages deleted", deleted_count); + tracing::debug!("{} Messages deleted", deleted_count); EphemeralMessage::create(&ctx.http, msg.channel_id, SHORT_TIMEOUT, |f| { f.content(format!("Deleted {} messages", deleted_count)) diff --git a/src/commands/misc/pain.rs b/src/commands/misc/pain.rs index 9a737d1..eb357a0 100644 --- a/src/commands/misc/pain.rs +++ b/src/commands/misc/pain.rs @@ -17,7 +17,7 @@ static NOT_FOUND_PAIN: &str = "404"; #[max_args(1)] #[bucket("general")] async fn pain(ctx: &Context, msg: &Message, args: Args) -> CommandResult { - log::debug!("Got pain command"); + tracing::debug!("Got pain command"); let pain_type = args.message().to_lowercase(); let database = get_database_from_context(ctx).await; let mut media = database @@ -25,7 +25,7 @@ async fn pain(ctx: &Context, msg: &Message, args: Args) -> CommandResult { .await?; if media.is_empty() { - log::debug!("No media found for pain {}. Using 404", pain_type); + tracing::debug!("No media found for pain {}. Using 404", pain_type); media = database .get_media_by_category(format!("{}{}", CATEGORY_PREFIX, NOT_FOUND_PAIN)) .await?; @@ -35,7 +35,7 @@ async fn pain(ctx: &Context, msg: &Message, args: Args) -> CommandResult { .into_iter() .choose(&mut rand::thread_rng()) .ok_or(BotError::from("No gifs found."))?; - log::trace!("Gif for pain is {:?}", entry); + tracing::trace!("Gif for pain is {:?}", entry); msg.reply(ctx, entry.url).await?; Ok(()) diff --git a/src/commands/misc/shutdown.rs b/src/commands/misc/shutdown.rs index 7911348..649672e 100644 --- a/src/commands/misc/shutdown.rs +++ b/src/commands/misc/shutdown.rs @@ -15,7 +15,7 @@ use crate::commands::common::handle_autodelete; #[owners_only] async fn shutdown(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { let code = args.single::().unwrap_or(0); - log::info!("Shutting down with code {}...", code); + tracing::info!("Shutting down with code {}...", code); msg.channel_id .say( ctx, diff --git a/src/commands/misc/stats.rs b/src/commands/misc/stats.rs index 31b1ed0..067f92d 100644 --- a/src/commands/misc/stats.rs +++ b/src/commands/misc/stats.rs @@ -16,7 +16,7 @@ use crate::utils::context_data::{get_database_from_context, MusicPlayers}; #[usage("")] #[bucket("general")] async fn stats(ctx: &Context, msg: &Message) -> CommandResult { - log::debug!("Reading system stats"); + tracing::debug!("Reading system stats"); let database = get_database_from_context(ctx).await; let mut system = sysinfo::System::new_all(); system.refresh_all(); @@ -56,7 +56,7 @@ async fn stats(ctx: &Context, msg: &Message) -> CommandResult { total_commands_executed ); - log::trace!("Discord info {}", discord_info); + tracing::trace!("Discord info {}", discord_info); let system_info = format!( r#" @@ -74,7 +74,7 @@ async fn stats(ctx: &Context, msg: &Message) -> CommandResult { uptime.num_hours() % 24, uptime.num_minutes() % 60 ); - log::trace!("System info {}", system_info); + tracing::trace!("System info {}", system_info); msg.channel_id .send_message(ctx, |m| { diff --git a/src/commands/music/clear_queue.rs b/src/commands/music/clear_queue.rs index 1318d40..03c3402 100644 --- a/src/commands/music/clear_queue.rs +++ b/src/commands/music/clear_queue.rs @@ -18,7 +18,7 @@ use serenity_rich_interaction::ephemeral_message::EphemeralMessage; #[checks(DJ)] async fn clear_queue(ctx: &Context, msg: &Message) -> CommandResult { let guild = msg.guild(&ctx.cache).await.unwrap(); - log::debug!("Clearing queue for guild {}", guild.id); + tracing::debug!("Clearing queue for guild {}", guild.id); let player = if let Some(player) = get_music_player_for_guild(ctx, guild.id).await { player diff --git a/src/commands/music/current.rs b/src/commands/music/current.rs index 8a75007..7cb70bd 100644 --- a/src/commands/music/current.rs +++ b/src/commands/music/current.rs @@ -17,7 +17,7 @@ use crate::messages::music::now_playing::create_now_playing_msg; async fn current(ctx: &Context, msg: &Message) -> CommandResult { let guild = msg.guild(&ctx.cache).await.unwrap(); - log::debug!("Displaying current song for queue in {}", guild.id); + tracing::debug!("Displaying current song for queue in {}", guild.id); let player = if let Some(player) = get_music_player_for_guild(ctx, guild.id).await { player } else { diff --git a/src/commands/music/equalize.rs b/src/commands/music/equalize.rs index 54d4264..764f314 100644 --- a/src/commands/music/equalize.rs +++ b/src/commands/music/equalize.rs @@ -19,7 +19,7 @@ use serenity_rich_interaction::ephemeral_message::EphemeralMessage; #[checks(DJ)] async fn equalize(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { let guild = msg.guild(&ctx.cache).await.unwrap(); - log::debug!("Changing equalizer for {}", guild.id); + tracing::debug!("Changing equalizer for {}", guild.id); let preset = args.single::().unwrap(); let player = if let Some(player) = get_music_player_for_guild(ctx, guild.id).await { diff --git a/src/commands/music/equalizer.rs b/src/commands/music/equalizer.rs index 3f68c36..10a07d4 100644 --- a/src/commands/music/equalizer.rs +++ b/src/commands/music/equalizer.rs @@ -16,7 +16,7 @@ use crate::messages::music::no_voicechannel::create_no_voicechannel_message; #[checks(DJ)] async fn equalizer(ctx: &Context, msg: &Message) -> CommandResult { let guild = msg.guild(&ctx.cache).await.unwrap(); - log::debug!("Displaying equalizer for guild {}", guild.id); + tracing::debug!("Displaying equalizer for guild {}", guild.id); let player = if let Some(player) = get_music_player_for_guild(ctx, guild.id).await { player diff --git a/src/commands/music/join.rs b/src/commands/music/join.rs index 04bea04..a7927c2 100644 --- a/src/commands/music/join.rs +++ b/src/commands/music/join.rs @@ -41,7 +41,7 @@ async fn join(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { .await?; return Ok(()); } - log::debug!("Joining channel {} for guild {}", channel_id, guild.id); + tracing::debug!("Joining channel {} for guild {}", channel_id, guild.id); MusicPlayer::join(ctx, guild.id, channel_id, msg.channel_id).await?; EphemeralMessage::create(&ctx.http, msg.channel_id, SHORT_TIMEOUT, |m| { m.content("🎤 Joined the Voice Channel") diff --git a/src/commands/music/leave.rs b/src/commands/music/leave.rs index 155e834..456d9da 100644 --- a/src/commands/music/leave.rs +++ b/src/commands/music/leave.rs @@ -18,7 +18,7 @@ use serenity_rich_interaction::ephemeral_message::EphemeralMessage; #[checks(DJ)] async fn leave(ctx: &Context, msg: &Message) -> CommandResult { let guild = msg.guild(&ctx.cache).await.unwrap(); - log::debug!("Leave request received for guild {}", guild.id); + tracing::debug!("Leave request received for guild {}", guild.id); let manager = songbird::get(ctx).await.unwrap(); if let Some(handler) = manager.get(guild.id) { diff --git a/src/commands/music/lyrics.rs b/src/commands/music/lyrics.rs index 98e63d7..1a6ca2b 100644 --- a/src/commands/music/lyrics.rs +++ b/src/commands/music/lyrics.rs @@ -14,7 +14,7 @@ use crate::messages::music::no_voicechannel::create_no_voicechannel_message; #[bucket("general")] async fn lyrics(ctx: &Context, msg: &Message) -> CommandResult { let guild = msg.guild(&ctx.cache).await.unwrap(); - log::debug!("Fetching lyrics for song playing in {}", guild.id); + tracing::debug!("Fetching lyrics for song playing in {}", guild.id); let player = if let Some(player) = get_music_player_for_guild(ctx, guild.id).await { player @@ -46,7 +46,7 @@ async fn lyrics(ctx: &Context, msg: &Message) -> CommandResult { }) .await?; } else { - log::debug!("No lyrics found"); + tracing::debug!("No lyrics found"); msg.channel_id.say(ctx, "No lyrics found").await?; } diff --git a/src/commands/music/mod.rs b/src/commands/music/mod.rs index d9c94bb..d37a830 100644 --- a/src/commands/music/mod.rs +++ b/src/commands/music/mod.rs @@ -126,23 +126,23 @@ async fn get_songs_for_query(ctx: &Context, msg: &Message, query: &str) -> BotRe let store = data.get::().unwrap(); let database = data.get::().unwrap(); - log::debug!("Querying play input {}", query); + tracing::debug!("Querying play input {}", query); if let Some(captures) = PLAYLIST_NAME_REGEX.captures(&query) { - log::debug!("Query is a saved playlist"); + tracing::debug!("Query is a saved playlist"); let pl_name: &str = captures.get(1).unwrap().as_str(); - log::trace!("Playlist name is {}", pl_name); + tracing::trace!("Playlist name is {}", pl_name); let playlist_opt = database .get_guild_playlist(guild_id.0, pl_name.to_string()) .await?; - log::trace!("Playlist is {:?}", playlist_opt); + tracing::trace!("Playlist is {:?}", playlist_opt); if let Some(playlist) = playlist_opt { - log::debug!("Assigning url for saved playlist to query"); + tracing::debug!("Assigning url for saved playlist to query"); query = playlist.url; } } if YOUTUBE_URL_REGEX.is_match(&query) { - log::debug!("Query is youtube video or playlist"); + tracing::debug!("Query is youtube video or playlist"); // try fetching the url as a playlist songs = youtube_dl::get_videos_for_playlist(&query) .await? @@ -152,18 +152,18 @@ async fn get_songs_for_query(ctx: &Context, msg: &Message, query: &str) -> BotRe // if no songs were found fetch the song as a video if songs.len() == 0 { - log::debug!("Query is youtube video"); + tracing::debug!("Query is youtube video"); let mut song: Song = get_video_information(&query).await?.into(); added_one_msg(&ctx, msg, &mut song).await?; add_youtube_song_to_database(&store, &database, &mut song).await?; songs.push(song); } else { - log::debug!("Query is playlist with {} songs", songs.len()); + tracing::debug!("Query is playlist with {} songs", songs.len()); added_multiple_msg(&ctx, msg, &mut songs).await?; } } else if SPOTIFY_PLAYLIST_REGEX.is_match(&query) { // search for all songs in the playlist and search for them on youtube - log::debug!("Query is spotify playlist"); + tracing::debug!("Query is spotify playlist"); let tracks = store.spotify_api.get_songs_in_playlist(&query).await?; let futures: Vec> = tracks @@ -183,7 +183,7 @@ async fn get_songs_for_query(ctx: &Context, msg: &Message, query: &str) -> BotRe added_multiple_msg(&ctx, msg, &mut songs).await?; } else if SPOTIFY_ALBUM_REGEX.is_match(&query) { // fetch all songs in the album and search for them on youtube - log::debug!("Query is spotify album"); + tracing::debug!("Query is spotify album"); let tracks = store.spotify_api.get_songs_in_album(&query).await?; for track in tracks { @@ -197,7 +197,7 @@ async fn get_songs_for_query(ctx: &Context, msg: &Message, query: &str) -> BotRe added_multiple_msg(&ctx, msg, &mut songs).await?; } else if SPOTIFY_SONG_REGEX.is_match(&query) { // fetch the song name and search it on youtube - log::debug!("Query is a spotify song"); + tracing::debug!("Query is a spotify song"); let track = store.spotify_api.get_track_for_url(&query).await?; let mut song = get_youtube_song_for_track(&database, track.clone()) .await? @@ -205,12 +205,12 @@ async fn get_songs_for_query(ctx: &Context, msg: &Message, query: &str) -> BotRe added_one_msg(ctx, msg, &mut song).await?; songs.push(song); } else { - log::debug!("Query is a youtube search"); + tracing::debug!("Query is a youtube search"); let mut song: Song = youtube_dl::search_video_information(query.clone()) .await? .ok_or(BotError::Msg(format!("Noting found for {}", query)))? .into(); - log::trace!("Search result is {:?}", song); + tracing::trace!("Search result is {:?}", song); added_one_msg(&ctx, msg, &mut song).await?; songs.push(song); @@ -291,24 +291,24 @@ pub async fn is_dj(ctx: &Context, guild: GuildId, user: &User) -> BotResult BotResult> { - log::debug!("Trying to find track in database."); + tracing::debug!("Trying to find track in database."); if let Some(id) = track.id { let entry = database.get_song(&id).await?; if let Some(song) = entry { // check if the video is still available - log::trace!("Found entry is {:?}", song); + tracing::trace!("Found entry is {:?}", song); if let Ok(info) = get_video_information(&song.url).await { return Ok(Some(info.into())); } else { - log::debug!("Video '{}' is not available. Deleting entry", song.url); + tracing::debug!("Video '{}' is not available. Deleting entry", song.url); database.delete_song(song.id).await?; return Ok(None); } } Ok(None) } else { - log::debug!("Track has no ID"); + tracing::debug!("Track has no ID"); Ok(None) } } diff --git a/src/commands/music/move_song.rs b/src/commands/music/move_song.rs index 383674c..ccea76c 100644 --- a/src/commands/music/move_song.rs +++ b/src/commands/music/move_song.rs @@ -19,7 +19,7 @@ use serenity_rich_interaction::ephemeral_message::EphemeralMessage; #[checks(DJ)] async fn move_song(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { let guild = msg.guild(&ctx.cache).await.unwrap(); - log::debug!("Moving song for guild {}", guild.id); + tracing::debug!("Moving song for guild {}", guild.id); let pos1 = args.single::()?; let pos2 = args.single::()?; diff --git a/src/commands/music/pause.rs b/src/commands/music/pause.rs index 6259cf4..34099aa 100644 --- a/src/commands/music/pause.rs +++ b/src/commands/music/pause.rs @@ -17,7 +17,7 @@ use serenity_rich_interaction::ephemeral_message::EphemeralMessage; #[checks(DJ)] async fn pause(ctx: &Context, msg: &Message) -> CommandResult { let guild = msg.guild(&ctx.cache).await.unwrap(); - log::debug!("Pausing playback for guild {}", guild.id); + tracing::debug!("Pausing playback for guild {}", guild.id); let player = if let Some(player) = get_music_player_for_guild(ctx, guild.id).await { player @@ -33,14 +33,14 @@ async fn pause(ctx: &Context, msg: &Message) -> CommandResult { let is_paused = player.is_paused(); if is_paused { - log::debug!("Paused"); + tracing::debug!("Paused"); EphemeralMessage::create(&ctx.http, msg.channel_id, SHORT_TIMEOUT, |m| { m.content("⏸️ Paused playback️") }) .await?; player.update_now_playing().await?; } else { - log::debug!("Resumed"); + tracing::debug!("Resumed"); EphemeralMessage::create(&ctx.http, msg.channel_id, SHORT_TIMEOUT, |m| { m.content("▶ Resumed playback️") }) diff --git a/src/commands/music/play.rs b/src/commands/music/play.rs index 9396cdc..164247e 100644 --- a/src/commands/music/play.rs +++ b/src/commands/music/play.rs @@ -23,12 +23,12 @@ async fn play(ctx: &Context, msg: &Message, args: Args) -> CommandResult { let query = args.message(); let guild = msg.guild(&ctx.cache).await.unwrap(); - log::debug!("Play request received for guild {}", guild.id); + tracing::debug!("Play request received for guild {}", guild.id); let mut player = get_music_player_for_guild(ctx, guild.id).await; if player.is_none() { - log::debug!("Not in a channel. Joining authors channel..."); + tracing::debug!("Not in a channel. Joining authors channel..."); let channel_id = get_channel_for_author(&msg.author.id, &guild)?; let music_player = MusicPlayer::join(ctx, guild.id, channel_id, msg.channel_id).await?; player = Some(music_player); @@ -37,7 +37,7 @@ async fn play(ctx: &Context, msg: &Message, args: Args) -> CommandResult { let songs = get_songs_for_query(&ctx, msg, query).await?; let (play_first, create_now_playing) = { - log::debug!("Adding song to queue"); + tracing::debug!("Adding song to queue"); let mut player_lock = player.lock().await; for song in songs { player_lock.queue().add(song); @@ -47,7 +47,7 @@ async fn play(ctx: &Context, msg: &Message, args: Args) -> CommandResult { .unwrap_or(false); if autoshuffle { - log::debug!("Autoshuffeling"); + tracing::debug!("Autoshuffeling"); player_lock.queue().shuffle(); } ( @@ -57,7 +57,7 @@ async fn play(ctx: &Context, msg: &Message, args: Args) -> CommandResult { }; if play_first { - log::debug!("Playing first song in queue"); + tracing::debug!("Playing first song in queue"); let mut player_lock = player.lock().await; player_lock.play_next().await?; } diff --git a/src/commands/music/play_next.rs b/src/commands/music/play_next.rs index ab62242..b8cb4d5 100644 --- a/src/commands/music/play_next.rs +++ b/src/commands/music/play_next.rs @@ -23,12 +23,12 @@ async fn play_next(ctx: &Context, msg: &Message, args: Args) -> CommandResult { let query = args.message(); let guild = msg.guild(&ctx.cache).await.unwrap(); - log::debug!("Playing song as next song for guild {}", guild.id); + tracing::debug!("Playing song as next song for guild {}", guild.id); let mut player = get_music_player_for_guild(ctx, guild.id).await; if player.is_none() { - log::debug!("Not in a channel. Joining authors channel..."); + tracing::debug!("Not in a channel. Joining authors channel..."); let channel_id = get_channel_for_author(&msg.author.id, &guild)?; let music_player = MusicPlayer::join(ctx, guild.id, channel_id, msg.channel_id).await?; player = Some(music_player); @@ -40,7 +40,7 @@ async fn play_next(ctx: &Context, msg: &Message, args: Args) -> CommandResult { let (play_first, create_now_playing) = { let mut player_lock = player.lock().await; songs.reverse(); - log::debug!("Enqueueing songs as next songs in the queue"); + tracing::debug!("Enqueueing songs as next songs in the queue"); for song in songs { player_lock.queue().add_next(song); diff --git a/src/commands/music/playlists.rs b/src/commands/music/playlists.rs index 2ebe6ac..87fa238 100644 --- a/src/commands/music/playlists.rs +++ b/src/commands/music/playlists.rs @@ -13,7 +13,7 @@ use crate::utils::context_data::get_database_from_context; #[bucket("general")] async fn playlists(ctx: &Context, msg: &Message) -> CommandResult { let guild = msg.guild(&ctx.cache).await.unwrap(); - log::debug!("Displaying playlists for guild {}", guild.id); + tracing::debug!("Displaying playlists for guild {}", guild.id); let database = get_database_from_context(ctx).await; let playlists = database.get_guild_playlists(guild.id.0).await?; diff --git a/src/commands/music/queue.rs b/src/commands/music/queue.rs index 2e611a2..f61a376 100644 --- a/src/commands/music/queue.rs +++ b/src/commands/music/queue.rs @@ -17,7 +17,7 @@ use crate::providers::music::queue::Song; #[bucket("general")] async fn queue(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { let guild = msg.guild(&ctx.cache).await.unwrap(); - log::trace!("Displaying queue for guild {}", guild.id); + tracing::trace!("Displaying queue for guild {}", guild.id); let query = args .iter::() @@ -53,7 +53,7 @@ async fn queue(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { }) .map(|(i, s)| (i, s.clone())) .collect(); - log::trace!("Songs are {:?}", songs); + tracing::trace!("Songs are {:?}", songs); if songs.len() == 0 { msg.channel_id diff --git a/src/commands/music/remove_song.rs b/src/commands/music/remove_song.rs index 28fd480..f5420fd 100644 --- a/src/commands/music/remove_song.rs +++ b/src/commands/music/remove_song.rs @@ -19,7 +19,7 @@ use serenity_rich_interaction::ephemeral_message::EphemeralMessage; #[checks(DJ)] async fn remove_song(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { let guild = msg.guild(&ctx.cache).await.unwrap(); - log::debug!("Moving song for guild {}", guild.id); + tracing::debug!("Moving song for guild {}", guild.id); let pos = args.single::()?; let player = if let Some(player) = get_music_player_for_guild(ctx, guild.id).await { diff --git a/src/commands/music/save_playlist.rs b/src/commands/music/save_playlist.rs index 57685bd..01bd983 100644 --- a/src/commands/music/save_playlist.rs +++ b/src/commands/music/save_playlist.rs @@ -20,7 +20,7 @@ async fn save_playlist(ctx: &Context, msg: &Message, mut args: Args) -> CommandR let name: String = args.single().unwrap(); let url: &str = args.remains().unwrap(); - log::debug!( + tracing::debug!( "Adding playlist '{}' with url '{}' to guild {}", name, url, diff --git a/src/commands/music/shuffle.rs b/src/commands/music/shuffle.rs index 37b155a..3564f13 100644 --- a/src/commands/music/shuffle.rs +++ b/src/commands/music/shuffle.rs @@ -19,7 +19,7 @@ use serenity_rich_interaction::ephemeral_message::EphemeralMessage; async fn shuffle(ctx: &Context, msg: &Message) -> CommandResult { let guild = msg.guild(&ctx.cache).await.unwrap(); - log::debug!("Shuffling queue for guild {}", guild.id); + tracing::debug!("Shuffling queue for guild {}", guild.id); let player = if let Some(player) = get_music_player_for_guild(ctx, guild.id).await { player } else { diff --git a/src/commands/music/skip.rs b/src/commands/music/skip.rs index dbf2bb0..be5f8db 100644 --- a/src/commands/music/skip.rs +++ b/src/commands/music/skip.rs @@ -18,7 +18,7 @@ use serenity_rich_interaction::ephemeral_message::EphemeralMessage; #[checks(DJ)] async fn skip(ctx: &Context, msg: &Message) -> CommandResult { let guild = msg.guild(&ctx.cache).await.unwrap(); - log::debug!("Skipping song for guild {}", guild.id); + tracing::debug!("Skipping song for guild {}", guild.id); let player = if let Some(player) = get_music_player_for_guild(ctx, guild.id).await { player diff --git a/src/commands/settings/get.rs b/src/commands/settings/get.rs index 280d485..a00c311 100644 --- a/src/commands/settings/get.rs +++ b/src/commands/settings/get.rs @@ -18,10 +18,10 @@ use crate::utils::context_data::get_database_from_context; async fn get(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { let database = get_database_from_context(ctx).await; let guild = msg.guild(&ctx.cache).await.unwrap(); - log::debug!("Displaying guild setting for guild {}", guild.id); + tracing::debug!("Displaying guild setting for guild {}", guild.id); if let Some(key) = args.single::().ok() { - log::debug!("Displaying guild setting of '{}'", key); + tracing::debug!("Displaying guild setting of '{}'", key); let setting = database .get_guild_setting::(guild.id.0, key.clone()) .await?; @@ -39,7 +39,7 @@ async fn get(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { } } } else { - log::debug!("Displaying all guild settings"); + tracing::debug!("Displaying all guild settings"); let mut kv_pairs = Vec::new(); for key in ALL_SETTINGS { diff --git a/src/commands/weeb/hololive/pekofy.rs b/src/commands/weeb/hololive/pekofy.rs index 9722ce5..8c6be52 100644 --- a/src/commands/weeb/hololive/pekofy.rs +++ b/src/commands/weeb/hololive/pekofy.rs @@ -43,7 +43,7 @@ async fn pekofy(ctx: &Context, msg: &Message, args: Args) -> CommandResult { return Err(CommandError::from("Can't pekofy empty message")); } - log::debug!("Pekofying message '{}'", content); + tracing::debug!("Pekofying message '{}'", content); let mut alpha_lowercase = content.to_lowercase(); alpha_lowercase.retain(|c| c.is_alphanumeric()); @@ -64,7 +64,7 @@ async fn pekofy(ctx: &Context, msg: &Message, args: Args) -> CommandResult { .http .get_message(msg.channel_id.0, reference_message.0) .await?; - log::debug!("Pekofied message is '{}'", pekofied); + tracing::debug!("Pekofied message is '{}'", pekofied); message.reply(ctx, pekofied).await?; Ok(()) @@ -73,7 +73,7 @@ async fn pekofy(ctx: &Context, msg: &Message, args: Args) -> CommandResult { /// Pekofies a single line fn pekofy_line(mut line: &str) -> String { lazy_static::lazy_static! { static ref FORMATTING_REGEX: Regex = Regex::new(r"^(.*?)((<:\w+:\d+>|\W)*)$").unwrap(); } - log::debug!("Pekofying line '{}'", line); + tracing::debug!("Pekofying line '{}'", line); let original = line; let mut md = ""; @@ -84,7 +84,7 @@ fn pekofy_line(mut line: &str) -> String { for peko in PEKOS { if line.to_lowercase().ends_with(peko) { - log::debug!("Peko already found in message. Returning original"); + tracing::debug!("Peko already found in message. Returning original"); return original.to_string(); } } @@ -96,7 +96,7 @@ fn pekofy_line(mut line: &str) -> String { .filter(|c| c.is_alphabetic()) .all(char::is_uppercase) { - log::debug!("Message is all uppercase. Peko will also be uppercase"); + tracing::debug!("Message is all uppercase. Peko will also be uppercase"); peko = peko.to_uppercase(); } diff --git a/src/commands/weeb/sauce.rs b/src/commands/weeb/sauce.rs index 9eea32d..2095f1d 100644 --- a/src/commands/weeb/sauce.rs +++ b/src/commands/weeb/sauce.rs @@ -16,17 +16,17 @@ use crate::utils::get_previous_message_or_reply; #[aliases("source")] #[bucket("sauce_api")] async fn sauce(ctx: &Context, msg: &Message) -> CommandResult { - log::debug!("Got sauce command"); + tracing::debug!("Got sauce command"); let source_msg = get_previous_message_or_reply(ctx, msg).await?; if source_msg.is_none() { - log::debug!("No source message provided"); + tracing::debug!("No source message provided"); msg.channel_id.say(ctx, "No source message found.").await?; return Ok(()); } let source_msg = source_msg.unwrap(); - log::trace!("Source message is {:?}", source_msg); - log::debug!("Getting attachments..."); + tracing::trace!("Source message is {:?}", source_msg); + tracing::debug!("Getting attachments..."); let mut attachment_urls: Vec = source_msg .attachments .into_iter() @@ -34,7 +34,7 @@ async fn sauce(ctx: &Context, msg: &Message) -> CommandResult { .filter(|url| url::is_image(url) || url::is_video(url)) .collect(); - log::debug!("Getting embedded images..."); + tracing::debug!("Getting embedded images..."); let mut embed_images = source_msg .embeds .into_iter() @@ -43,17 +43,17 @@ async fn sauce(ctx: &Context, msg: &Message) -> CommandResult { .collect::>(); attachment_urls.append(&mut embed_images); - log::trace!("Image urls {:?}", attachment_urls); + tracing::trace!("Image urls {:?}", attachment_urls); if attachment_urls.is_empty() { - log::debug!("No images in source image"); + tracing::debug!("No images in source image"); msg.channel_id .say(ctx, "I could not find any images in the message.") .await?; return Ok(()); } - log::debug!( + tracing::debug!( "Checking SauceNao for {} attachments", attachment_urls.len() ); @@ -63,12 +63,12 @@ async fn sauce(ctx: &Context, msg: &Message) -> CommandResult { .sauce_nao .check_sauces(&attachment_urls[..]) .await?; - log::trace!("Sources are {:?}", sources); + tracing::trace!("Sources are {:?}", sources); - log::debug!("Creating menu..."); + tracing::debug!("Creating menu..."); show_sauce_menu(ctx, msg, sources).await?; - log::debug!("Menu created"); + tracing::debug!("Menu created"); Ok(()) } diff --git a/src/handler.rs b/src/handler.rs index 70baed9..9453d49 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -22,7 +22,7 @@ pub fn get_raw_event_handler() -> RichEventHandler { .add_event(|ctx, e: &event::ReadyEvent| Box::pin(ready(ctx, &e.ready))) .add_event(|_ctx, _: &event::ResumedEvent| { Box::pin(async { - log::info!("Reconnected to Gateway"); + tracing::info!("Reconnected to Gateway"); Ok(()) }) }); @@ -31,7 +31,7 @@ pub fn get_raw_event_handler() -> RichEventHandler { } async fn ready(ctx: &Context, _: &Ready) -> Result<()> { - log::info!("Ready"); + tracing::info!("Ready"); delete_messages_from_database(&ctx).await?; let prefix = std::env::var("BOT_PREFIX").unwrap_or("~!".to_string()); ctx.set_activity(Activity::listening(format!("{}help", prefix).as_str())) @@ -44,7 +44,7 @@ pub(crate) struct Handler; #[async_trait] impl EventHandler for Handler { async fn resume(&self, _: Context, _: ResumedEvent) { - log::info!("Reconnected to gateway") + tracing::info!("Reconnected to gateway") } async fn voice_state_update( @@ -72,10 +72,10 @@ impl EventHandler for Handler { } if let Some(count) = member_count { - log::debug!("{} Members in channel", count); + tracing::debug!("{} Members in channel", count); if let Some(player) = get_music_player_for_guild(&ctx, guild_id).await { let mut player = player.lock().await; - log::debug!("Setting leave flag to {}", count == 0); + tracing::debug!("Setting leave flag to {}", count == 0); player.set_leave_flag(count == 0); } } diff --git a/src/main.rs b/src/main.rs index 1f9a387..0436d45 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,11 +17,11 @@ async fn main() { init_logger(); let mut client = get_client() .await - .map_err(|e| log::error!("Failed to get client: {:?}", e)) + .map_err(|e| tracing::error!("Failed to get client: {:?}", e)) .expect("Failed to get client"); // start listening for events by starting a single shard if let Err(why) = client.start_autosharded().await { - log::error!("An error occurred while running the client: {:?}", why); + tracing::error!("An error occurred while running the client: {:?}", why); } } diff --git a/src/messages/music/now_playing.rs b/src/messages/music/now_playing.rs index b8bf4b2..5fa69c6 100644 --- a/src/messages/music/now_playing.rs +++ b/src/messages/music/now_playing.rs @@ -33,7 +33,7 @@ pub async fn create_now_playing_msg( player: Arc>, channel_id: ChannelId, ) -> BotResult>> { - log::debug!("Creating now playing menu"); + tracing::debug!("Creating now playing menu"); let nsfw = channel_id.to_channel(ctx).await?.is_nsfw(); let handle = MenuBuilder::default() .add_control(-1, DELETE_BUTTON, |c, m, r| { @@ -63,9 +63,9 @@ pub async fn create_now_playing_msg( .add_page(Page::new_builder(move || { let player = Arc::clone(&player); Box::pin(async move { - log::debug!("Creating now playing embed for page"); + tracing::debug!("Creating now playing embed for page"); let mut player = player.lock().await; - log::debug!("player locked"); + tracing::debug!("player locked"); let mut page = CreateMessage::default(); if let Some(mut current) = player.queue().current().clone() { @@ -79,7 +79,7 @@ pub async fn create_now_playing_msg( } else { page.embed(|e| e.description("Queue is empty")); } - log::debug!("Embed created"); + tracing::debug!("Embed created"); Ok(page) }) @@ -101,7 +101,7 @@ pub async fn update_now_playing_msg( song: &mut Song, paused: bool, ) -> BotResult<()> { - log::debug!("Updating now playing message"); + tracing::debug!("Updating now playing message"); let handle = handle.read().await; let mut message = handle.get_message(http).await?; let nsfw = http.get_channel(handle.channel_id).await?.is_nsfw(); @@ -116,7 +116,7 @@ pub async fn update_now_playing_msg( }) }) .await?; - log::debug!("Message updated."); + tracing::debug!("Message updated."); Ok(()) } @@ -159,7 +159,7 @@ async fn play_pause_button_action( _: &mut Menu<'_>, reaction: Reaction, ) -> SerenityUtilsResult<()> { - log::debug!("Play/Pause button pressed"); + tracing::debug!("Play/Pause button pressed"); let guild_id = reaction.guild_id.unwrap(); let user = reaction.user(&ctx).await?; @@ -170,7 +170,7 @@ async fn play_pause_button_action( let player = get_music_player_for_guild(ctx, guild_id).await.unwrap(); let (current, message, paused) = { - log::debug!("Queue is locked"); + tracing::debug!("Queue is locked"); let mut player = player.lock().await; player.toggle_paused().await?; ( @@ -179,7 +179,7 @@ async fn play_pause_button_action( player.is_paused(), ) }; - log::debug!("Queue is unlocked"); + tracing::debug!("Queue is unlocked"); if let Some(mut current) = current { update_now_playing_msg(&ctx.http, &message, &mut current, paused).await?; @@ -243,9 +243,9 @@ async fn stop_button_action( player.stop().await?; } - log::debug!("Left the voice channel"); + tracing::debug!("Left the voice channel"); } else { - log::debug!("Not in a voice channel"); + tracing::debug!("Not in a voice channel"); } } { diff --git a/src/providers/minecraft.rs b/src/providers/minecraft.rs index 1d9b8ff..ee66bf5 100644 --- a/src/providers/minecraft.rs +++ b/src/providers/minecraft.rs @@ -34,7 +34,7 @@ pub fn get_item_full_information(name: &str, api: &Api) -> BotResult().unwrap(); @@ -29,20 +29,20 @@ impl LavalinkEventHandler for LavalinkHandler { if let Some(player) = player { let mut player = player.lock().await; if let Err(e) = player.play_next().await { - log::error!("Failed to play next song: {:?}", e); + tracing::error!("Failed to play next song: {:?}", e); } if let Err(e) = player.update_now_playing().await { - log::error!("Failed to update now playing embed: {:?}", e); + tracing::error!("Failed to update now playing embed: {:?}", e); } } } async fn player_update(&self, _: LavalinkClient, event: PlayerUpdate) { - log::debug!("Received player update event: {:?}", event); + tracing::debug!("Received player update event: {:?}", event); } async fn stats(&self, _: LavalinkClient, event: Stats) { - log::debug!("Received stats event: {:?}", event); + tracing::debug!("Received stats event: {:?}", event); } } diff --git a/src/providers/music/lyrics.rs b/src/providers/music/lyrics.rs index efdb340..e413b01 100644 --- a/src/providers/music/lyrics.rs +++ b/src/providers/music/lyrics.rs @@ -8,12 +8,12 @@ const API_ENDPOINT: &str = "https://api.lyrics.ovh/v1/"; /// Returns the lyrics of a song pub async fn get_lyrics(artist: &str, title: &str) -> BotResult> { lazy_static::lazy_static! { static ref DOUBLE_LB_REGEX: Regex = Regex::new(r"\n\n").unwrap(); } - log::debug!("Requesting lyrics for '{}' by '{}'", title, artist); + tracing::debug!("Requesting lyrics for '{}' by '{}'", title, artist); let request_url = format!("{}{}/{}", API_ENDPOINT, artist, title); - log::trace!("Request url is {}", request_url); + tracing::trace!("Request url is {}", request_url); let response = reqwest::get(request_url).await?; let response_text = response.text().await?; - log::trace!("Lyrics Response is {}", response_text); + tracing::trace!("Lyrics Response is {}", response_text); let lyrics: Option = serde_json::from_str(&*response_text).ok(); diff --git a/src/providers/music/mod.rs b/src/providers/music/mod.rs index f52f521..8d438d6 100644 --- a/src/providers/music/mod.rs +++ b/src/providers/music/mod.rs @@ -41,12 +41,12 @@ pub(crate) async fn song_to_youtube_video(song: &Song) -> BotResult match search_for_song_variations(store, song).await { Ok(Some(track)) => track, Err(e) => { - log::error!("Failed to search for song on spotify {:?}", e); + tracing::error!("Failed to search for song on spotify {:?}", e); return Ok(()); } _ => return Ok(()), }, }; - log::debug!("Song found on spotify. Inserting metadata"); + tracing::debug!("Song found on spotify. Inserting metadata"); let artists = artists_to_string(track.artists); let url = song.url().await.unwrap(); @@ -93,7 +93,7 @@ async fn search_for_song_variations( let mut query = COMMON_ADDITIONS.replace_all(song.title(), " ").to_string(); query = query.replace(|c| c != ' ' && !char::is_alphanumeric(c), ""); - log::debug!("Searching for youtube song"); + tracing::debug!("Searching for youtube song"); if let Some(track) = store.spotify_api.search_for_song(&query).await? { let similarity = trigram::similarity( &format!( @@ -104,12 +104,12 @@ async fn search_for_song_variations( &query, ); if similarity > 0.3 { - log::debug!("Result is similar enough ({}). Returning track", similarity); + tracing::debug!("Result is similar enough ({}). Returning track", similarity); return Ok(Some(track)); } - log::debug!("Result is not similar enough"); + tracing::debug!("Result is not similar enough"); } - log::debug!("No result found"); + tracing::debug!("No result found"); Ok(None) } diff --git a/src/providers/music/player.rs b/src/providers/music/player.rs index 6da9b95..43fac0b 100644 --- a/src/providers/music/player.rs +++ b/src/providers/music/player.rs @@ -137,7 +137,7 @@ impl MusicPlayer { /// Tries to play the next song pub async fn try_play_next(&mut self) -> BotResult { let mut next = if let Some(n) = self.queue.next() { - log::trace!("Next is {:?}", n); + tracing::trace!("Next is {:?}", n); n } else { return Ok(true); @@ -151,13 +151,13 @@ impl MusicPlayer { next.author() )) .await?; - log::debug!("Could not find playable candidate for song."); + tracing::debug!("Could not find playable candidate for song."); return Ok(false); }; let query_information = match self.client.auto_search_tracks(url).await { Ok(i) => i, Err(e) => { - log::error!("Failed to search for song: {}", e); + tracing::error!("Failed to search for song: {}", e); self.send_error_message(format!( "‼️ Failed to retrieve information for song '{}' by '{}': {:?}", next.title(), @@ -292,10 +292,10 @@ fn wait_for_disconnect( let mut player_lock = player.lock().await; if player_lock.leave_flag { - log::debug!("Waiting to leave"); + tracing::debug!("Waiting to leave"); if leave_in <= 0 { - log::debug!("Leaving voice channel"); + tracing::debug!("Leaving voice channel"); if let Some(handler) = manager.get(guild_id) { let mut handler_lock = handler.lock().await; @@ -308,12 +308,12 @@ fn wait_for_disconnect( players.remove(&guild_id.0); let _ = player_lock.stop().await; let _ = player_lock.delete_now_playing().await; - log::debug!("Left the voice channel"); + tracing::debug!("Left the voice channel"); return; } leave_in -= 1; } else { - log::debug!("Resetting leave value"); + tracing::debug!("Resetting leave value"); leave_in = 5 } } diff --git a/src/providers/music/queue.rs b/src/providers/music/queue.rs index d4cee95..1d86c16 100644 --- a/src/providers/music/queue.rs +++ b/src/providers/music/queue.rs @@ -99,7 +99,7 @@ impl Song { if let Some(url) = self.url.clone() { Some(url) } else { - log::debug!("Lazy fetching video for title"); + tracing::debug!("Lazy fetching video for title"); let information = song_to_youtube_video(&self).await.ok()??; self.url = Some(information.webpage_url.clone()); self.thumbnail = information.thumbnail; diff --git a/src/providers/music/spotify.rs b/src/providers/music/spotify.rs index 20bf1c5..2cc5ccd 100644 --- a/src/providers/music/spotify.rs +++ b/src/providers/music/spotify.rs @@ -15,21 +15,21 @@ impl SpotifyApi { secret: dotenv::var("SPOTIFY_CLIENT_SECRET").expect("Missing Spotify Credentials"), }; let client = Client::new(credentials); - log::info!("Spotify API initialized."); + tracing::info!("Spotify API initialized."); Self { client } } /// Searches for a song on spotify pub async fn search_for_song(&self, query: &str) -> BotResult> { - log::debug!("Searching for song '{}' on spotify", query); + tracing::debug!("Searching for song '{}' on spotify", query); let types = vec![ItemType::Track]; let result = self .client .search() .search(query, types, false, 1, 0, None) .await?; - log::trace!("Result is {:?}", result); + tracing::trace!("Result is {:?}", result); let tracks = result .data .tracks @@ -40,7 +40,7 @@ impl SpotifyApi { /// Returns the songs for a playlist pub async fn get_songs_in_playlist(&self, url: &str) -> BotResult> { - log::debug!("Fetching spotify songs from playlist '{}'", url); + tracing::debug!("Fetching spotify songs from playlist '{}'", url); let id = self.get_id_for_url(url)?; let mut playlist_tracks = Vec::new(); let mut offset = 0; @@ -53,13 +53,13 @@ impl SpotifyApi { playlist_tracks.append(&mut tracks); offset += 100; } - log::debug!( + tracing::debug!( "{} Songs found in spotify playlist '{}'", playlist_tracks.len(), url ); - log::trace!("Songs are {:?}", playlist_tracks); + tracing::trace!("Songs are {:?}", playlist_tracks); Ok(playlist_tracks) } @@ -71,7 +71,7 @@ impl SpotifyApi { limit: usize, offset: usize, ) -> BotResult> { - log::trace!( + tracing::trace!( "Fetching songs from spotify playlist: limit {}, offset {}", limit, offset @@ -92,17 +92,17 @@ impl SpotifyApi { PlaylistItemType::Episode(_) => None, }) .collect(); - log::trace!("Tracks are {:?}", tracks); + tracing::trace!("Tracks are {:?}", tracks); Ok(tracks) } /// Returns all songs for a given album pub async fn get_songs_in_album(&self, url: &str) -> BotResult> { - log::debug!("Fetching songs for spotify album '{}'", url); + tracing::debug!("Fetching songs for spotify album '{}'", url); let id = self.get_id_for_url(url)?; let album = self.client.albums().get_album(&*id, None).await?.data; - log::trace!("Album is {:?}", album); + tracing::trace!("Album is {:?}", album); let simple_tracks: Vec = album .tracks @@ -117,17 +117,17 @@ impl SpotifyApi { .await? .data; - log::trace!("Tracks are {:?}", tracks); + tracing::trace!("Tracks are {:?}", tracks); Ok(tracks) } /// Returns song entity for a given spotify url pub async fn get_track_for_url(&self, url: &str) -> BotResult { - log::debug!("Getting song for {}", url); + tracing::debug!("Getting song for {}", url); let id = self.get_id_for_url(url)?; let track = self.client.tracks().get_track(&*id, None).await?.data; - log::trace!("Track info is {:?}", track); + tracing::trace!("Track info is {:?}", track); Ok(track) } diff --git a/src/providers/music/youtube_dl.rs b/src/providers/music/youtube_dl.rs index 4bb5027..a0b4a26 100644 --- a/src/providers/music/youtube_dl.rs +++ b/src/providers/music/youtube_dl.rs @@ -16,7 +16,7 @@ static THREAD_LIMIT: u8 = 64; /// Returns a list of youtube videos for a given url pub(crate) async fn get_videos_for_playlist(url: &str) -> BotResult> { - log::debug!("Getting playlist information for {}", url); + tracing::debug!("Getting playlist information for {}", url); let output = youtube_dl(&["--no-warnings", "--flat-playlist", "--dump-json", "-i", url]).await?; @@ -30,7 +30,7 @@ pub(crate) async fn get_videos_for_playlist(url: &str) -> BotResult BotResult> { - log::debug!("Searching for video '{}'", query); + tracing::debug!("Searching for video '{}'", query); let output = youtube_dl(&[ "--no-warnings", "--dump-json", @@ -63,7 +63,7 @@ async fn parallel_search_youtube(song_names: Vec) -> Vec { /// to avoid using too much memory async fn youtube_dl(args: &[&str]) -> BotResult { lazy_static::lazy_static! { static ref THREAD_LOCK: Arc = Arc::new(AtomicU8::new(0)); } - log::trace!("Running youtube-dl with args {:?}", args); + tracing::trace!("Running youtube-dl with args {:?}", args); while THREAD_LOCK.load(Ordering::SeqCst) >= THREAD_LIMIT { tokio::time::sleep(Duration::from_millis(100)).await; @@ -74,7 +74,7 @@ async fn youtube_dl(args: &[&str]) -> BotResult { THREAD_LOCK.fetch_sub(1, Ordering::Relaxed); e })?; - log::trace!("youtube-dl response is {}", output); + tracing::trace!("youtube-dl response is {}", output); THREAD_LOCK.fetch_sub(1, Ordering::Relaxed); Ok(output) diff --git a/src/utils/logging.rs b/src/utils/logging.rs index e79b2a8..33eb4fd 100644 --- a/src/utils/logging.rs +++ b/src/utils/logging.rs @@ -4,86 +4,23 @@ * See LICENSE for more information */ -use std::fs; -use std::path::PathBuf; use std::str::FromStr; -use chrono::Local; -use colored::*; -use log::{Level, LevelFilter}; +use tracing_subscriber::fmt::format::FmtSpan; +use tracing_subscriber::EnvFilter; -/// Initializes the env_logger with a custom format -/// that also logs the thread names -pub fn init_logger() { - let log_dir = PathBuf::from(dotenv::var("LOG_DIR").unwrap_or("logs".to_string())); - - if !log_dir.exists() { - fs::create_dir(&log_dir).expect("failed to create log dir"); - } - fern::Dispatch::new() - .format(|out, message, record| { - let color = get_level_style(record.level()); - let mut target = record.target().to_string(); - target.truncate(39); +const DEFAULT_ENV_FILTER: &str = "info,serenity=warn"; - out.finish(format_args!( - "{:<40}| {} {}: {}", - target.dimmed().italic(), - Local::now().format("%Y-%m-%dT%H:%M:%S"), - record - .level() - .to_string() - .to_lowercase() - .as_str() - .color(color), - message - )) - }) - .level( - log::LevelFilter::from_str( - std::env::var("RUST_LOG") - .unwrap_or("info".to_string()) - .as_str(), - ) - .unwrap_or(LevelFilter::Info), - ) - .level_for("tokio", log::LevelFilter::Info) - .level_for("tracing", log::LevelFilter::Warn) - .level_for("serenity", log::LevelFilter::Warn) - .level_for("rustls", log::LevelFilter::Warn) - .level_for("h2", log::LevelFilter::Warn) - .level_for("reqwest", log::LevelFilter::Warn) - .level_for("tungstenite", log::LevelFilter::Warn) - .level_for("hyper", log::LevelFilter::Warn) - .level_for("async_tungstenite", log::LevelFilter::Warn) - .level_for("tokio_util", log::LevelFilter::Warn) - .level_for("want", log::LevelFilter::Warn) - .level_for("mio", log::LevelFilter::Warn) - .level_for("songbird", log::LevelFilter::Warn) - .level_for("html5ever", log::LevelFilter::Warn) - .level_for("scraper", log::LevelFilter::Warn) - .level_for("html5ever", log::LevelFilter::Warn) - .level_for("cssparser", log::LevelFilter::Warn) - .level_for("selectors", log::LevelFilter::Warn) - .level_for("matches", log::LevelFilter::Warn) - .chain(std::io::stdout()) - .chain( - fern::log_file(log_dir.join(PathBuf::from(format!( - "{}.log", - Local::now().format("%Y-%m-%d"), - )))) - .expect("failed to create log file"), - ) - .apply() - .expect("failed to init logger"); -} - -fn get_level_style(level: Level) -> colored::Color { - match level { - Level::Trace => colored::Color::Magenta, - Level::Debug => colored::Color::Blue, - Level::Info => colored::Color::Green, - Level::Warn => colored::Color::Yellow, - Level::Error => colored::Color::Red, - } +/// Initializes tracing +pub fn init_logger() { + let filter_string = + std::env::var("RUST_LOG").unwrap_or_else(|_| DEFAULT_ENV_FILTER.to_string()); + let env_filter = + EnvFilter::from_str(&*filter_string).expect("failed to parse env filter string"); + tracing_subscriber::fmt::SubscriberBuilder::default() + .with_env_filter(env_filter) + .with_writer(std::io::stdout) + .with_span_events(FmtSpan::NEW | FmtSpan::CLOSE) + .compact() + .init(); } diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 3c8ad8a..c218201 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -56,7 +56,7 @@ pub async fn delete_messages_from_database(ctx: &Context) -> BotResult<()> { for message in messages { if message.timeout <= SystemTime::now() { - log::debug!("Deleting message {:?}", message); + tracing::debug!("Deleting message {:?}", message); let _ = ctx .http .delete_message(message.channel_id as u64, message.message_id as u64) @@ -67,7 +67,7 @@ pub async fn delete_messages_from_database(ctx: &Context) -> BotResult<()> { } else { let http = Arc::clone(&ctx.http); let database = database.clone(); - log::debug!( + tracing::debug!( "Creating future to delete ephemeral message {:?} later", message ); @@ -77,7 +77,7 @@ pub async fn delete_messages_from_database(ctx: &Context) -> BotResult<()> { Instant::now().add(message.timeout.duration_since(SystemTime::now()).unwrap()), ) .await; - log::debug!("Deleting message {:?}", message); + tracing::debug!("Deleting message {:?}", message); let _ = http .delete_message(message.channel_id as u64, message.message_id as u64) .await;