diff --git a/Cargo.lock b/Cargo.lock index 9244793..dfb7ce7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1175,6 +1175,15 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + [[package]] name = "matrix-sdk" version = "0.6.2" @@ -1822,8 +1831,17 @@ checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" dependencies = [ "aho-corasick", "memchr", - "regex-automata", - "regex-syntax", + "regex-automata 0.4.3", + "regex-syntax 0.8.2", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", ] [[package]] @@ -1834,9 +1852,15 @@ checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" dependencies = [ "aho-corasick", "memchr", - "regex-syntax", + "regex-syntax 0.8.2", ] +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + [[package]] name = "regex-syntax" version = "0.8.2" @@ -2466,10 +2490,14 @@ version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" dependencies = [ + "matchers", "nu-ansi-term", + "once_cell", + "regex", "sharded-slab", "smallvec", "thread_local", + "tracing", "tracing-core", "tracing-log", ] diff --git a/Cargo.toml b/Cargo.toml index 1ada33b..97e857b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,4 +12,4 @@ dotenvy = "0.15.7" matrix-sdk = { version = "0.6.2", features = ["anyhow", "markdown"] } tokio = { version = "1.34.0", features = ["macros", "rt-multi-thread", "full"] } tracing = "0.1.40" -tracing-subscriber = "0.3.18" +tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } diff --git a/src/main.rs b/src/main.rs index f59f94b..6b6bdf6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,11 +31,11 @@ async fn autojoin_room(room_member: matrix_sdk::ruma::events::room::member::Stri let mut delay = 2; let r = client.get_invited_room(rid).unwrap(); while let Err(err) = r.accept_invitation().await { - eprintln!("Failed to join room {} ({err:?}), retrying in {delay}s", room.room_id()); + tracing::error!("Failed to join room {} ({err:?}), retrying in {delay}s", room.room_id()); tokio::time::sleep(tokio::time::Duration::from_secs(delay)).await; delay *= 2; if delay > 3600 { - eprintln!("Can't join room {} ({err:?})", room.room_id()); + tracing::error!("Can't join room {} ({err:?})", room.room_id()); break; } } @@ -69,7 +69,7 @@ async fn connect_to_matrix(hs: String, username: String, passwd:String) -> anyho } } - println!("Logged in as {username}"); + tracing::info!("Logged in as {username}"); let response = client.sync_once(matrix_sdk::config::SyncSettings::default()).await?; client.add_event_handler(on_room_message); client.add_event_handler(autojoin_room); @@ -82,7 +82,16 @@ async fn connect_to_matrix(hs: String, username: String, passwd:String) -> anyho #[tokio::main] async fn main() -> anyhow::Result<()> { dotenvy::dotenv().ok(); - tracing_subscriber::fmt::init(); + let filter = tracing_subscriber::EnvFilter::from_default_env() + .add_directive(tracing_subscriber::filter::LevelFilter::WARN.into()) + .add_directive("diru_bot=debug".parse()?); + tracing_subscriber::fmt() + .with_env_filter(filter) + .with_level(true) + .with_target(true) + .with_ansi(true) + .compact() + .init(); let (homeserver_url, username, passwd) = match (std::env::var("HOMESERVER_URL"), std::env::var("MATRIX_BOT_NAME"), std::env::var("MATRIX_BOT_PASSWD")) { (Ok(a), Ok(b), Ok(c)) => (a, b, c),