diff --git a/Cargo.lock b/Cargo.lock index 2fcae34..f3642d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,6 +30,15 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "android-tzdata" version = "0.1.1" @@ -46,16 +55,53 @@ dependencies = [ ] [[package]] -name = "anyhow" -version = "1.0.95" +name = "anstream" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] [[package]] -name = "arc-swap" -version = "1.7.1" +name = "anstyle" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" + +[[package]] +name = "anstyle-parse" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" +dependencies = [ + "anstyle", + "windows-sys 0.59.0", +] [[package]] name = "async-trait" @@ -216,6 +262,12 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "colorchoice" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" + [[package]] name = "convert_case" version = "0.4.0" @@ -341,12 +393,6 @@ dependencies = [ "syn 2.0.93", ] -[[package]] -name = "destructure_traitobject" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c877555693c14d2f84191cfd3ad8582790fc52b5e2274b40b59cf5f5cea25c7" - [[package]] name = "digest" version = "0.10.7" @@ -390,6 +436,29 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "env_filter" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcaee3d8e3cfc3fd92428d477bc97fc29ec8716d180c0d74c643bb26166660e0" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -885,6 +954,12 @@ version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "itoa" version = "1.0.14" @@ -940,44 +1015,6 @@ name = "log" version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" -dependencies = [ - "serde", -] - -[[package]] -name = "log-mdc" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a94d21414c1f4a51209ad204c1776a3d0765002c76c6abcb602a6f09f1e881c7" - -[[package]] -name = "log4rs" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0816135ae15bd0391cf284eab37e6e3ee0a6ee63d2ceeb659862bd8d0a984ca6" -dependencies = [ - "anyhow", - "arc-swap", - "chrono", - "derivative", - "flate2", - "fnv", - "humantime", - "libc", - "log", - "log-mdc", - "once_cell", - "parking_lot", - "rand", - "serde", - "serde-value", - "serde_json", - "serde_yaml", - "thiserror", - "thread-id", - "typemap-ors", - "winapi", -] [[package]] name = "lru-cache" @@ -1272,6 +1309,35 @@ dependencies = [ "bitflags 2.6.0", ] +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + [[package]] name = "reqwest" version = "0.11.27" @@ -1568,19 +1634,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "serde_yaml" -version = "0.9.34+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" -dependencies = [ - "indexmap", - "itoa", - "ryu", - "serde", - "unsafe-libyaml", -] - [[package]] name = "serenity" version = "0.11.7" @@ -1815,16 +1868,6 @@ dependencies = [ "syn 2.0.93", ] -[[package]] -name = "thread-id" -version = "4.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfe8f25bbdd100db7e1d34acf7fd2dc59c4bf8f7483f505eaa7d4f12f76cc0ea" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "time" version = "0.3.37" @@ -2065,15 +2108,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "typemap-ors" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a68c24b707f02dd18f1e4ccceb9d49f2058c2fb86384ef9972592904d7a28867" -dependencies = [ - "unsafe-any-ors", -] - [[package]] name = "typemap_rev" version = "0.1.5" @@ -2119,21 +2153,6 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e70f2a8b45122e719eb623c01822704c4e0907e7e426a05927e1a1cfff5b75d0" -[[package]] -name = "unsafe-any-ors" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a303d30665362d9680d7d91d78b23f5f899504d4f08b3c4cf08d055d87c0ad" -dependencies = [ - "destructure_traitobject", -] - -[[package]] -name = "unsafe-libyaml" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" - [[package]] name = "untrusted" version = "0.7.1" @@ -2176,6 +2195,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "uuid" version = "1.11.0" @@ -2377,6 +2402,15 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-targets" version = "0.48.5" @@ -2557,9 +2591,9 @@ dependencies = [ name = "yorokobot" version = "0.2.1" dependencies = [ + "env_logger", "futures", "log", - "log4rs", "mongodb", "serde", "serenity", diff --git a/Cargo.toml b/Cargo.toml index 780ab24..01f6ec9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,9 +14,9 @@ serenity = { version="0.11", default-features = false, features = ["client", "ga tokio = { version = "1", features = ["macros", "rt-multi-thread"] } mongodb = { version = "2.3.0", default-features = false, features = ["tokio-runtime"] } serde = { version = "1.0", features = [ "derive" ] } -log4rs = { version = "1.2.0", features = [ "console_appender", "rolling_file_appender", "compound_policy", "fixed_window_roller", "size_trigger", "gzip", "background_rotation" ] } log = "0.4.17" futures = "0.3.25" +env_logger = "0.11.6" [lints.rust] unsafe_code= "forbid" diff --git a/src/logs.rs b/src/logs.rs deleted file mode 100644 index 26d320d..0000000 --- a/src/logs.rs +++ /dev/null @@ -1,64 +0,0 @@ -use log::LevelFilter; - -use log4rs::{ - append::{ - console::ConsoleAppender, - rolling_file::{ - policy::compound::{ - roll::fixed_window::FixedWindowRoller, trigger::size::SizeTrigger, CompoundPolicy, - }, - RollingFileAppender, - }, - }, - config::{Appender, Logger, Root}, - encode::pattern::PatternEncoder, - Config, -}; - -const FILE_MAX_SIZE: u64 = 30000000; //30 mB -const LOGS_MAX_FILES: u32 = 10; - -const LOG_FORMAT: &str = "{d(%Y-%m-%d %H:%M:%S)} | {({l}):5.5} | {f}:{L} — {m}{n}"; -const LOGS_FILE: &str = "logs/yorokobot_latest.log"; -const LOGS_ARCHIVE_FILE_PATTERN: &str = "logs/yorokobot_{}.gz"; - -/// Configure the bot logger -pub fn init_logger() -> log4rs::Handle { - // Rollings logs trigger - let size_triger = SizeTrigger::new(FILE_MAX_SIZE); - - // Rolling logs rollers - let logs_roller = FixedWindowRoller::builder() - .base(1) - .build(LOGS_ARCHIVE_FILE_PATTERN, LOGS_MAX_FILES) - .unwrap(); - - // Rolling logs policies - let rolling_logs_policy = CompoundPolicy::new(Box::new(size_triger), Box::new(logs_roller)); - - // Appenders - let stdout = ConsoleAppender::builder() - .encoder(Box::new(PatternEncoder::new(LOG_FORMAT))) - .build(); - let rolling_logs = RollingFileAppender::builder() - .encoder(Box::new(PatternEncoder::new(LOG_FORMAT))) - .build(LOGS_FILE, Box::new(rolling_logs_policy)) - .unwrap(); - - let config = Config::builder() - .appender(Appender::builder().build("stdout", Box::new(stdout))) - .appender(Appender::builder().build("rolling_logs", Box::new(rolling_logs))) - // Don't print the serenity crate logs - .logger(Logger::builder().build("serenity", LevelFilter::Error)) - // Don't print the tracing crate logs - .logger(Logger::builder().build("tracing", LevelFilter::Error)) - .build( - Root::builder() - .appender("stdout") - .appender("rolling_logs") - .build(LevelFilter::Info), - ) - .unwrap(); - - log4rs::init_config(config).unwrap() -} diff --git a/src/main.rs b/src/main.rs index f5671fe..7737f5a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,16 +7,12 @@ mod client; mod database; mod discord; mod environment; -mod logs; use client::Client; -use logs::init_logger; #[tokio::main] async fn main() { - // Start the logger - let _handle = init_logger(); - + env_logger::init(); let mut client = Client::new().await; client.start().await;