diff --git a/Cargo.lock b/Cargo.lock index aa8d170b8..e71f11f3f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -311,6 +311,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + [[package]] name = "anyhow" version = "1.0.45" @@ -365,17 +374,6 @@ dependencies = [ "quick-xml", ] -[[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 = "autocfg" version = "0.1.7" @@ -1104,19 +1102,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5320ae4c3782150d900b79807611a59a99fc9a1d61d686faafc24b93fc8d7ca" -[[package]] -name = "env_logger" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" -dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", -] - [[package]] name = "event-listener" version = "2.5.1" @@ -1557,12 +1542,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - [[package]] name = "hyper" version = "0.14.15" @@ -1769,7 +1748,6 @@ dependencies = [ "lemmy_db_views_moderator", "lemmy_utils", "lemmy_websocket", - "log", "openssl", "rand 0.8.4", "reqwest", @@ -1796,7 +1774,6 @@ dependencies = [ "lemmy_db_views_actor", "lemmy_db_views_moderator", "lemmy_utils", - "log", "serde", "serde_json", "url", @@ -1830,7 +1807,6 @@ dependencies = [ "lemmy_db_views_moderator", "lemmy_utils", "lemmy_websocket", - "log", "openssl", "rand 0.8.4", "reqwest", @@ -1841,6 +1817,7 @@ dependencies = [ "strum_macros", "thiserror", "tokio", + "tracing", "url", "uuid", "webmention", @@ -1874,7 +1851,6 @@ dependencies = [ "lemmy_db_views_actor", "lemmy_utils", "lemmy_websocket", - "log", "once_cell", "percent-encoding", "rand 0.8.4", @@ -1888,6 +1864,7 @@ dependencies = [ "strum_macros", "thiserror", "tokio", + "tracing", "url", "uuid", ] @@ -1908,13 +1885,13 @@ dependencies = [ "http-signature-normalization-reqwest", "lemmy_apub_lib_derive", "lemmy_utils", - "log", "once_cell", "openssl", "reqwest", "serde", "serde_json", "sha2", + "tracing", "url", ] @@ -1939,7 +1916,6 @@ dependencies = [ "diesel_migrations", "lemmy_apub_lib", "lemmy_utils", - "log", "once_cell", "regex", "serde", @@ -1957,9 +1933,9 @@ version = "0.14.1" dependencies = [ "diesel", "lemmy_db_schema", - "log", "serde", "serial_test", + "tracing", "url", ] @@ -2000,7 +1976,6 @@ dependencies = [ "lemmy_db_views_actor", "lemmy_utils", "lemmy_websocket", - "log", "once_cell", "rss", "serde", @@ -2024,7 +1999,6 @@ dependencies = [ "diesel", "diesel_migrations", "doku", - "env_logger", "http-signature-normalization-actix", "lemmy_api", "lemmy_api_common", @@ -2038,13 +2012,17 @@ dependencies = [ "lemmy_routes", "lemmy_utils", "lemmy_websocket", - "log", "openssl", "reqwest", "serde", "serde_json", "strum", "tokio", + "tracing", + "tracing-actix-web", + "tracing-error", + "tracing-log", + "tracing-subscriber", "url", ] @@ -2065,7 +2043,6 @@ dependencies = [ "itertools", "jsonwebtoken", "lettre", - "log", "once_cell", "openssl", "percent-encoding", @@ -2079,6 +2056,8 @@ dependencies = [ "strum_macros", "thiserror", "tokio", + "tracing", + "tracing-error", "url", "uuid", "webpage", @@ -2100,7 +2079,6 @@ dependencies = [ "lemmy_db_views", "lemmy_db_views_actor", "lemmy_utils", - "log", "rand 0.8.4", "reqwest", "serde", @@ -2108,6 +2086,7 @@ dependencies = [ "strum", "strum_macros", "tokio", + "tracing", ] [[package]] @@ -2257,6 +2236,15 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" +[[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" @@ -3102,6 +3090,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" @@ -3998,6 +3995,19 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-actix-web" +version = "0.5.0-beta.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cac34827e06f78b69523b2fbe5b2dd4dfc75940b2ea5ba37e4fa2a25d4a0edf" +dependencies = [ + "actix-web", + "pin-project", + "tracing", + "tracing-futures", + "uuid", +] + [[package]] name = "tracing-attributes" version = "0.1.18" @@ -4038,15 +4048,33 @@ 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.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80a4ddde70311d8da398062ecf6fc2c309337de6b0f77d6c27aff8d53f6fca52" +checksum = "7507ec620f809cdf07cccb5bc57b13069a88031b795efd4079b1c71b66c1613d" dependencies = [ + "ansi_term", + "lazy_static", + "matchers", + "regex", "sharded-slab", + "smallvec", "thread_local", + "tracing", "tracing-core", + "tracing-log", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index c210b5a7e..bd247b7d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,8 +49,11 @@ chrono = { version = "0.4.19", features = ["serde"] } serde = { version = "1.0.130", features = ["derive"] } actix = "0.12.0" actix-web = { version = "4.0.0-beta.9", default-features = false, features = ["rustls"] } -log = "0.4.14" -env_logger = "0.9.0" +tracing = "0.1.29" +tracing-actix-web = "0.5.0-beta.2" +tracing-error = "0.2.0" +tracing-log = "0.1.2" +tracing-subscriber = { version = "0.3.2", features = ["env-filter"] } strum = "0.21.0" url = { version = "2.2.2", features = ["serde"] } openssl = "0.10.36" diff --git a/crates/api/Cargo.toml b/crates/api/Cargo.toml index 7d53cb330..b2db6e690 100644 --- a/crates/api/Cargo.toml +++ b/crates/api/Cargo.toml @@ -31,7 +31,6 @@ actix = "0.12.0" actix-web = { version = "4.0.0-beta.9", default-features = false } actix-rt = { version = "2.2.0", default-features = false } awc = { version = "3.0.0-beta.8", default-features = false } -log = "0.4.14" rand = "0.8.4" strum = "0.21.0" strum_macros = "0.21.1" diff --git a/crates/api_common/Cargo.toml b/crates/api_common/Cargo.toml index 608574d2e..9b7c56403 100644 --- a/crates/api_common/Cargo.toml +++ b/crates/api_common/Cargo.toml @@ -19,7 +19,6 @@ lemmy_db_views_actor = { version = "=0.14.1", path = "../db_views_actor" } lemmy_db_schema = { version = "=0.14.1", path = "../db_schema" } lemmy_utils = { version = "=0.14.1", path = "../utils" } serde = { version = "1.0.130", features = ["derive"] } -log = "0.4.14" diesel = "1.4.8" actix-web = { version = "4.0.0-beta.9", default-features = false, features = ["cookies"] } chrono = { version = "0.4.19", features = ["serde"] } diff --git a/crates/api_crud/Cargo.toml b/crates/api_crud/Cargo.toml index 6372ebf4f..f18871073 100644 --- a/crates/api_crud/Cargo.toml +++ b/crates/api_crud/Cargo.toml @@ -26,7 +26,7 @@ actix = "0.12.0" actix-web = { version = "4.0.0-beta.9", default-features = false } actix-rt = { version = "2.2.0", default-features = false } awc = { version = "3.0.0-beta.8", default-features = false } -log = "0.4.14" +tracing = "0.1.29" rand = "0.8.4" strum = "0.21.0" strum_macros = "0.21.1" diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index 248adee6c..a4a92f255 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -32,7 +32,7 @@ use lemmy_utils::{ LemmyError, }; use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud}; -use log::warn; +use tracing::warn; use url::Url; use webmention::{Webmention, WebmentionError}; diff --git a/crates/api_crud/src/site/read.rs b/crates/api_crud/src/site/read.rs index cfe492048..837acc83c 100644 --- a/crates/api_crud/src/site/read.rs +++ b/crates/api_crud/src/site/read.rs @@ -17,7 +17,7 @@ use lemmy_db_views_actor::{ }; use lemmy_utils::{version, ApiError, ConnectionId, LemmyError}; use lemmy_websocket::{messages::GetUsersOnline, LemmyContext}; -use log::info; +use tracing::info; #[async_trait::async_trait(?Send)] impl PerformCrud for GetSite { diff --git a/crates/apub/Cargo.toml b/crates/apub/Cargo.toml index 8e5c312df..b2140270f 100644 --- a/crates/apub/Cargo.toml +++ b/crates/apub/Cargo.toml @@ -31,7 +31,7 @@ actix = "0.12.0" actix-web = { version = "4.0.0-beta.9", default-features = false } actix-rt = { version = "2.2.0", default-features = false } awc = { version = "3.0.0-beta.8", default-features = false } -log = "0.4.14" +tracing = "0.1.29" rand = "0.8.4" strum = "0.21.0" strum_macros = "0.21.1" diff --git a/crates/apub/src/activities/mod.rs b/crates/apub/src/activities/mod.rs index 07fc39d2f..1a3d01bbe 100644 --- a/crates/apub/src/activities/mod.rs +++ b/crates/apub/src/activities/mod.rs @@ -21,8 +21,8 @@ use lemmy_db_views_actor::{ }; use lemmy_utils::{settings::structs::Settings, LemmyError}; use lemmy_websocket::LemmyContext; -use log::info; use serde::Serialize; +use tracing::info; use url::{ParseError, Url}; use uuid::Uuid; diff --git a/crates/apub/src/fetcher/webfinger.rs b/crates/apub/src/fetcher/webfinger.rs index d1878d287..93986a50f 100644 --- a/crates/apub/src/fetcher/webfinger.rs +++ b/crates/apub/src/fetcher/webfinger.rs @@ -11,8 +11,8 @@ use lemmy_utils::{ LemmyError, }; use lemmy_websocket::LemmyContext; -use log::debug; use serde::{Deserialize, Serialize}; +use tracing::debug; use url::Url; #[derive(Serialize, Deserialize, Debug)] diff --git a/crates/apub/src/http/community.rs b/crates/apub/src/http/community.rs index 6b95626d5..b040a4a80 100644 --- a/crates/apub/src/http/community.rs +++ b/crates/apub/src/http/community.rs @@ -27,8 +27,8 @@ use lemmy_apub_lib::{object_id::ObjectId, traits::ApubObject}; use lemmy_db_schema::source::community::Community; use lemmy_utils::LemmyError; use lemmy_websocket::LemmyContext; -use log::info; use serde::Deserialize; +use tracing::info; #[derive(Deserialize)] pub(crate) struct CommunityQuery { diff --git a/crates/apub/src/http/mod.rs b/crates/apub/src/http/mod.rs index 03eb9e5bf..0d484e8f8 100644 --- a/crates/apub/src/http/mod.rs +++ b/crates/apub/src/http/mod.rs @@ -27,9 +27,9 @@ use lemmy_apub_lib::{ use lemmy_db_schema::source::activity::Activity; use lemmy_utils::{location_info, LemmyError}; use lemmy_websocket::LemmyContext; -use log::info; use serde::{Deserialize, Serialize}; use std::{fmt::Debug, io::Read}; +use tracing::info; use url::Url; mod comment; diff --git a/crates/apub/src/http/person.rs b/crates/apub/src/http/person.rs index 3a3a34038..b98f189c9 100644 --- a/crates/apub/src/http/person.rs +++ b/crates/apub/src/http/person.rs @@ -17,8 +17,8 @@ use lemmy_apub_lib::traits::ApubObject; use lemmy_db_schema::source::person::Person; use lemmy_utils::LemmyError; use lemmy_websocket::LemmyContext; -use log::info; use serde::Deserialize; +use tracing::info; #[derive(Deserialize)] pub struct PersonQuery { diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index 300ad2f2c..72d9c0c27 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -25,8 +25,8 @@ use lemmy_utils::{ LemmyError, }; use lemmy_websocket::LemmyContext; -use log::debug; use std::ops::Deref; +use tracing::debug; use url::Url; #[derive(Clone, Debug)] diff --git a/crates/apub_lib/Cargo.toml b/crates/apub_lib/Cargo.toml index 1e30cd8d6..31f41dfc2 100644 --- a/crates/apub_lib/Cargo.toml +++ b/crates/apub_lib/Cargo.toml @@ -17,7 +17,7 @@ url = { version = "2.2.2", features = ["serde"] } serde_json = { version = "1.0.68", features = ["preserve_order"] } anyhow = "1.0.44" reqwest = { version = "0.11.4", features = ["json"] } -log = "0.4.14" +tracing = "0.1.29" base64 = "0.13.0" openssl = "0.10.36" once_cell = "1.8.0" diff --git a/crates/apub_lib/src/activity_queue.rs b/crates/apub_lib/src/activity_queue.rs index 31b18f7c0..582997e29 100644 --- a/crates/apub_lib/src/activity_queue.rs +++ b/crates/apub_lib/src/activity_queue.rs @@ -10,10 +10,10 @@ use background_jobs::{ WorkerConfig, }; use lemmy_utils::{location_info, LemmyError}; -use log::{info, warn}; use reqwest::Client; use serde::{Deserialize, Serialize}; use std::{env, fmt::Debug, future::Future, pin::Pin}; +use tracing::{info, warn}; use url::Url; pub async fn send_activity( diff --git a/crates/apub_lib/src/object_id.rs b/crates/apub_lib/src/object_id.rs index 7d3be9e5e..59898e669 100644 --- a/crates/apub_lib/src/object_id.rs +++ b/crates/apub_lib/src/object_id.rs @@ -7,7 +7,6 @@ use lemmy_utils::{ settings::structs::Settings, LemmyError, }; -use log::info; use once_cell::sync::Lazy; use reqwest::{Client, StatusCode}; use serde::{Deserialize, Serialize}; @@ -16,6 +15,7 @@ use std::{ marker::PhantomData, time::Duration, }; +use tracing::info; use url::Url; /// Maximum number of HTTP requests allowed to handle a single incoming activity (or a single object diff --git a/crates/apub_lib/src/signatures.rs b/crates/apub_lib/src/signatures.rs index 2ba7edd47..36c6b9644 100644 --- a/crates/apub_lib/src/signatures.rs +++ b/crates/apub_lib/src/signatures.rs @@ -5,7 +5,6 @@ use http::{header::HeaderName, HeaderMap, HeaderValue}; use http_signature_normalization_actix::Config as ConfigActix; use http_signature_normalization_reqwest::prelude::{Config, SignExt}; use lemmy_utils::LemmyError; -use log::debug; use once_cell::sync::Lazy; use openssl::{ hash::MessageDigest, @@ -16,6 +15,7 @@ use reqwest::{Client, Response}; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; use std::str::FromStr; +use tracing::debug; use url::Url; static CONFIG2: Lazy = Lazy::new(ConfigActix::new); diff --git a/crates/db_schema/Cargo.toml b/crates/db_schema/Cargo.toml index b7e486911..f57228b6f 100644 --- a/crates/db_schema/Cargo.toml +++ b/crates/db_schema/Cargo.toml @@ -18,7 +18,6 @@ diesel_migrations = "1.4.0" chrono = { version = "0.4.19", features = ["serde"] } serde = { version = "1.0.130", features = ["derive"] } serde_json = { version = "1.0.68", features = ["preserve_order"] } -log = "0.4.14" url = { version = "2.2.2", features = ["serde"] } diesel-derive-newtype = "0.1.2" regex = "1.5.4" diff --git a/crates/db_views/Cargo.toml b/crates/db_views/Cargo.toml index 34e59030d..338b83021 100644 --- a/crates/db_views/Cargo.toml +++ b/crates/db_views/Cargo.toml @@ -14,7 +14,7 @@ doctest = false lemmy_db_schema = { version = "=0.14.1", path = "../db_schema" } diesel = { version = "1.4.8", features = ["postgres","chrono","r2d2","serde_json"] } serde = { version = "1.0.130", features = ["derive"] } -log = "0.4.14" +tracing = "0.1.29" url = "2.2.2" [dev-dependencies] diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index 897a78e00..db7c76cda 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -28,8 +28,8 @@ use lemmy_db_schema::{ ListingType, SortType, }; -use log::debug; use serde::{Deserialize, Serialize}; +use tracing::debug; #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] pub struct PostView { diff --git a/crates/db_views/src/private_message_view.rs b/crates/db_views/src/private_message_view.rs index 940dbd366..8996f2292 100644 --- a/crates/db_views/src/private_message_view.rs +++ b/crates/db_views/src/private_message_view.rs @@ -9,8 +9,8 @@ use lemmy_db_schema::{ }, traits::{MaybeOptional, ToSafe, ViewToVec}, }; -use log::debug; use serde::{Deserialize, Serialize}; +use tracing::debug; #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] pub struct PrivateMessageView { diff --git a/crates/routes/Cargo.toml b/crates/routes/Cargo.toml index 00b17133e..357ae8a18 100644 --- a/crates/routes/Cargo.toml +++ b/crates/routes/Cargo.toml @@ -24,7 +24,6 @@ actix-web = { version = "4.0.0-beta.9", default-features = false, features = ["r actix-web-actors = { version = "4.0.0-beta.7", default-features = false } actix-http = "3.0.0-beta.10" sha2 = "0.9.8" -log = "0.4.14" anyhow = "1.0.44" chrono = { version = "0.4.19", features = ["serde"] } rss = "1.10.0" diff --git a/crates/utils/Cargo.toml b/crates/utils/Cargo.toml index fa75be691..02c6caddd 100644 --- a/crates/utils/Cargo.toml +++ b/crates/utils/Cargo.toml @@ -16,7 +16,8 @@ doctest = false regex = "1.5.4" chrono = { version = "0.4.19", features = ["serde"] } lettre = "0.10.0-rc.3" -log = "0.4.14" +tracing = "0.1.29" +tracing-error = "0.2.0" itertools = "0.10.1" rand = "0.8.4" percent-encoding = "2.1.0" diff --git a/crates/utils/src/lib.rs b/crates/utils/src/lib.rs index e30150e30..5eaff30e8 100644 --- a/crates/utils/src/lib.rs +++ b/crates/utils/src/lib.rs @@ -16,9 +16,10 @@ pub mod utils; pub mod version; use http::StatusCode; -use log::warn; use std::{fmt, fmt::Display}; use thiserror::Error; +use tracing::warn; +use tracing_error::SpanTrace; pub type ConnectionId = usize; @@ -66,6 +67,7 @@ impl ApiError { #[derive(Debug)] pub struct LemmyError { pub inner: anyhow::Error, + pub context: SpanTrace, } impl From for LemmyError @@ -73,13 +75,17 @@ where T: Into, { fn from(t: T) -> Self { - LemmyError { inner: t.into() } + LemmyError { + inner: t.into(), + context: SpanTrace::capture(), + } } } impl Display for LemmyError { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - self.inner.fmt(f) + self.inner.fmt(f)?; + self.context.fmt(f) } } diff --git a/crates/utils/src/rate_limit/rate_limiter.rs b/crates/utils/src/rate_limit/rate_limiter.rs index 352d5e66b..468199153 100644 --- a/crates/utils/src/rate_limit/rate_limiter.rs +++ b/crates/utils/src/rate_limit/rate_limiter.rs @@ -1,7 +1,7 @@ use crate::{ApiError, IpAddr, LemmyError}; -use log::debug; use std::{collections::HashMap, time::SystemTime}; use strum::IntoEnumIterator; +use tracing::debug; #[derive(Debug, Clone)] struct RateLimitBucket { diff --git a/crates/utils/src/request.rs b/crates/utils/src/request.rs index d8bd11a3a..c2434f86b 100644 --- a/crates/utils/src/request.rs +++ b/crates/utils/src/request.rs @@ -1,11 +1,11 @@ use crate::{settings::structs::Settings, version::VERSION, LemmyError}; use anyhow::anyhow; -use log::error; use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC}; use reqwest::Client; use serde::{Deserialize, Serialize}; use std::future::Future; use thiserror::Error; +use tracing::error; use url::Url; use webpage::HTML; diff --git a/crates/websocket/Cargo.toml b/crates/websocket/Cargo.toml index 8d4f192de..2f91826a7 100644 --- a/crates/websocket/Cargo.toml +++ b/crates/websocket/Cargo.toml @@ -19,7 +19,7 @@ lemmy_db_schema = { version = "=0.14.1", path = "../db_schema" } lemmy_db_views = { version = "=0.14.1", path = "../db_views" } lemmy_db_views_actor = { version = "=0.14.1", path = "../db_views_actor" } reqwest = { version = "0.11.4", features = ["json"] } -log = "0.4.14" +tracing = "0.1.29" rand = "0.8.4" serde = { version = "1.0.130", features = ["derive"] } serde_json = { version = "1.0.68", features = ["preserve_order"] } diff --git a/crates/websocket/src/handlers.rs b/crates/websocket/src/handlers.rs index 5c3a1735c..1e67cdb31 100644 --- a/crates/websocket/src/handlers.rs +++ b/crates/websocket/src/handlers.rs @@ -6,9 +6,9 @@ use crate::{ use actix::{Actor, Context, Handler, ResponseFuture}; use lemmy_db_schema::naive_now; use lemmy_utils::ConnectionId; -use log::{error, info}; use rand::Rng; use serde::Serialize; +use tracing::{error, info}; /// Make actor from `ChatServer` impl Actor for ChatServer { diff --git a/crates/websocket/src/routes.rs b/crates/websocket/src/routes.rs index 8a487813e..e5551b418 100644 --- a/crates/websocket/src/routes.rs +++ b/crates/websocket/src/routes.rs @@ -7,8 +7,8 @@ use actix::prelude::*; use actix_web::*; use actix_web_actors::ws; use lemmy_utils::{utils::get_ip, ConnectionId, IpAddr}; -use log::{debug, error, info}; use std::time::{Duration, Instant}; +use tracing::{debug, error, info}; /// How often heartbeat pings are sent const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5); diff --git a/crates/websocket/src/send.rs b/crates/websocket/src/send.rs index 85f24f12e..ccb29879e 100644 --- a/crates/websocket/src/send.rs +++ b/crates/websocket/src/send.rs @@ -34,7 +34,7 @@ use lemmy_utils::{ ConnectionId, LemmyError, }; -use log::error; +use tracing::error; pub async fn send_post_ws_message( post_id: PostId, diff --git a/src/code_migrations.rs b/src/code_migrations.rs index b7c43508b..4737066bb 100644 --- a/src/code_migrations.rs +++ b/src/code_migrations.rs @@ -22,7 +22,7 @@ use lemmy_db_schema::{ traits::Crud, }; use lemmy_utils::{apub::generate_actor_keypair, LemmyError}; -use log::info; +use tracing::info; pub fn run_advanced_migrations( conn: &PgConnection, diff --git a/src/lib.rs b/src/lib.rs index ea79cbb08..98c2320d1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,3 +2,27 @@ pub mod api_routes; pub mod code_migrations; pub mod scheduled_tasks; + +use lemmy_utils::LemmyError; +use tracing::subscriber::set_global_default; +use tracing_error::ErrorLayer; +use tracing_log::LogTracer; +use tracing_subscriber::{fmt::format::FmtSpan, layer::SubscriberExt, EnvFilter, Registry}; + +pub fn init_tracing() -> Result<(), LemmyError> { + LogTracer::init()?; + + let env_filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")); + let format_layer = tracing_subscriber::fmt::layer() + .with_span_events(FmtSpan::NEW | FmtSpan::CLOSE) + .pretty(); + + let subscriber = Registry::default() + .with(env_filter) + .with(format_layer) + .with(ErrorLayer::default()); + + set_global_default(subscriber)?; + + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index 059262a03..c5e777b1d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,12 @@ use lemmy_api_crud::match_websocket_operation_crud; use lemmy_apub_lib::activity_queue::create_activity_queue; use lemmy_db_schema::{get_database_url_from_env, source::secret::Secret}; use lemmy_routes::{feeds, images, nodeinfo, webfinger}; -use lemmy_server::{api_routes, code_migrations::run_advanced_migrations, scheduled_tasks}; +use lemmy_server::{ + api_routes, + code_migrations::run_advanced_migrations, + init_tracing, + scheduled_tasks, +}; use lemmy_utils::{ rate_limit::{rate_limiter::RateLimiter, RateLimit}, request::build_user_agent, @@ -25,6 +30,7 @@ use lemmy_websocket::{chat_server::ChatServer, LemmyContext}; use reqwest::Client; use std::{env, sync::Arc, thread}; use tokio::sync::Mutex; +use tracing_actix_web::TracingLogger; embed_migrations!(); @@ -40,7 +46,8 @@ async fn main() -> Result<(), LemmyError> { return Ok(()); } - env_logger::init(); + init_tracing()?; + let settings = Settings::init().expect("Couldn't initialize settings."); // Set up the r2d2 connection pool @@ -114,7 +121,7 @@ async fn main() -> Result<(), LemmyError> { ); let rate_limiter = rate_limiter.clone(); App::new() - .wrap(middleware::Logger::default()) + .wrap(TracingLogger::default()) .app_data(Data::new(context)) // The routes .configure(|cfg| api_routes::config(cfg, &rate_limiter)) diff --git a/src/scheduled_tasks.rs b/src/scheduled_tasks.rs index c3514d63e..f416fb7b4 100644 --- a/src/scheduled_tasks.rs +++ b/src/scheduled_tasks.rs @@ -4,8 +4,8 @@ use clokwerk::{Scheduler, TimeUnits}; use diesel::{sql_query, PgConnection, RunQueryDsl}; use lemmy_db_schema::{source::activity::Activity, DbPool}; use lemmy_utils::LemmyError; -use log::info; use std::{thread, time::Duration}; +use tracing::info; /// Schedules various cleanup tasks for lemmy in a background thread pub fn setup(pool: DbPool) -> Result<(), LemmyError> {