Skip to content

Commit

Permalink
dev: move from log and fern to tracing with subscriber
Browse files Browse the repository at this point in the history
  • Loading branch information
da2ce7 committed Apr 9, 2024
1 parent ebb9bc5 commit 9f71c47
Show file tree
Hide file tree
Showing 57 changed files with 286 additions and 264 deletions.
93 changes: 69 additions & 24 deletions Cargo.lock

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

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ colored = "2"
config = "0"
crossbeam-skiplist = "0.1"
derive_more = "0"
fern = "0"
futures = "0"
hex-literal = "0"
hyper = "1"
lazy_static = "1"
log = { version = "0", features = ["release_max_level_info"] }
multimap = "0"
percent-encoding = "2"
r2d2 = "0"
Expand All @@ -71,8 +69,8 @@ torrust-tracker-located-error = { version = "3.0.0-alpha.12-develop", path = "pa
torrust-tracker-primitives = { version = "3.0.0-alpha.12-develop", path = "packages/primitives" }
torrust-tracker-torrent-repository = { version = "3.0.0-alpha.12-develop", path = "packages/torrent-repository" }
tower-http = { version = "0", features = ["compression-full", "cors", "propagate-header", "request-id", "trace"] }
trace = "0"
tracing = "0"
tracing-subscriber = "0"
url = "2"
uuid = { version = "1", features = ["v4"] }

Expand Down
6 changes: 3 additions & 3 deletions docs/benchmarking.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ cargo build --release -p aquatic_udp_load_test
Run the tracker with UDP service enabled and other services disabled and set log level to `error`.

```toml
log_level = "error"
trace_level = "error"

[[udp_trackers]]
enabled = true
Expand All @@ -55,7 +55,7 @@ Output:
```output
Starting client with config: Config {
server_address: 127.0.0.1:6969,
log_level: Error,
trace_level: Error,
workers: 1,
duration: 0,
summarize_last: 0,
Expand Down Expand Up @@ -163,7 +163,7 @@ Announce responses per info hash:
Run the tracker with UDP service enabled and other services disabled and set log level to `error`.

```toml
log_level = "error"
trace_level = "error"

[[udp_trackers]]
enabled = true
Expand Down
50 changes: 41 additions & 9 deletions packages/configuration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@
//! RequestHeader set X-Forwarded-Proto "https"
//! RequestHeader set X-Forwarded-Port "443"
//!
//! ErrorLog ${APACHE_LOG_DIR}/tracker.torrust.com-error.log
//! CustomLog ${APACHE_LOG_DIR}/tracker.torrust.com-access.log combined
//! ErrorLog ${APACHE_LOG_DIR}/tracker.torrust.com-error.tracing
//! CustomLog ${APACHE_LOG_DIR}/tracker.torrust.com-access.tracing combined
//!
//! SSLCertificateFile CERT_PATH
//! SSLCertificateKeyFile CERT_KEY_PATH
Expand Down Expand Up @@ -196,7 +196,7 @@
//! db_path = "./storage/tracker/lib/database/sqlite3.db"
//! external_ip = "0.0.0.0"
//! inactive_peer_cleanup_interval = 600
//! log_level = "info"
//! trace_level = "info"
//! max_peer_timeout = 900
//! min_announce_interval = 120
//! mode = "public"
Expand Down Expand Up @@ -236,7 +236,7 @@ use std::sync::Arc;
use std::{env, fs};

use config::{Config, ConfigError, File, FileFormat};
use derive_more::Constructor;
use derive_more::{AsRef, Constructor};
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, NoneAsEmptyString};
use thiserror::Error;
Expand Down Expand Up @@ -431,13 +431,45 @@ impl Default for AnnouncePolicy {
}
}

#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, AsRef)]
#[serde(transparent)]
pub struct TraceLevel {
level: String,
}

impl TraceLevel {
#[must_use]
pub fn new(level: &str) -> Self {
Self {
level: level.to_ascii_lowercase().to_string(),
}
}
}

impl std::fmt::Display for TraceLevel {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.level.to_ascii_uppercase())
}
}

impl Default for TraceLevel {
fn default() -> Self {
Self::new("info")
}
}

/// Core configuration for the tracker.
#[allow(clippy::struct_excessive_bools)]
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
pub struct Configuration {
/// Logging level. Possible values are: `Off`, `Error`, `Warn`, `Info`,
/// `Debug` and `Trace`. Default is `Info`.
pub log_level: Option<String>,
/// Maximum Verbosity Level for Trace Subscription.

Check warning on line 465 in packages/configuration/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

packages/configuration/src/lib.rs#L465

Added line #L465 was not covered by tests
///
/// Possible values are: `Off`, `Error`, `Warn`, `Info`, `Debug` and `Trace`.
///
/// Default is `Info`.
#[serde(default, alias = "log_level", alias = "trace_level")]
pub tracing_max_verbosity_level: TraceLevel,

/// Tracker mode. See [`TrackerMode`] for more information.
pub mode: TrackerMode,

Expand Down Expand Up @@ -544,7 +576,7 @@ impl Default for Configuration {
let announce_policy = AnnouncePolicy::default();

let mut configuration = Configuration {
log_level: Option::from(String::from("info")),
tracing_max_verbosity_level: TraceLevel::default(),
mode: TrackerMode::Public,
db_driver: DatabaseDriver::Sqlite3,
db_path: String::from("./storage/tracker/lib/database/sqlite3.db"),
Expand Down Expand Up @@ -686,7 +718,7 @@ mod tests {

#[cfg(test)]
fn default_config_toml() -> String {
let config = r#"log_level = "info"
let config = r#"tracing_max_verbosity_level = "info"
mode = "public"
db_driver = "Sqlite3"
db_path = "./storage/tracker/lib/database/sqlite3.db"
Expand Down
2 changes: 1 addition & 1 deletion packages/located-error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rust-version.workspace = true
version.workspace = true

[dependencies]
log = { version = "0", features = ["release_max_level_info"] }
tracing = "0"

[dev-dependencies]
thiserror = "1"
2 changes: 1 addition & 1 deletion packages/located-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use std::error::Error;
use std::panic::Location;
use std::sync::Arc;

use log::debug;
use tracing::debug;

pub type DynError = Arc<dyn std::error::Error + Send + Sync>;

Expand Down
6 changes: 3 additions & 3 deletions packages/test-helpers/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::env;
use std::net::IpAddr;

use torrust_tracker_configuration::Configuration;
use torrust_tracker_configuration::{Configuration, TraceLevel};
use torrust_tracker_primitives::TrackerMode;

use crate::random;
Expand All @@ -15,7 +15,7 @@ use crate::random;
/// > **NOTICE**: Port 0 is used for ephemeral ports, which means that the OS
/// will assign a random free port for the tracker to use.
///
/// > **NOTICE**: You can change the log level to `debug` to see the logs of the
/// > **NOTICE**: You can change the tracing level to `debug` to see the traces of the
/// tracker while running the tests. That can be particularly useful when
/// debugging tests.
///
Expand All @@ -28,7 +28,7 @@ pub fn ephemeral() -> Configuration {
// For example: a test for the UDP tracker should disable the API and HTTP tracker.

let mut config = Configuration {
log_level: Some("off".to_owned()), // Change to `debug` for tests debugging
tracing_max_verbosity_level: TraceLevel::new("off"), // Change to `debug` for tests debugging
..Default::default()
};

Expand Down
2 changes: 1 addition & 1 deletion share/default/config/tracker.container.mysql.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ db_driver = "MySQL"
db_path = "mysql://db_user:db_user_secret_password@mysql:3306/torrust_tracker"
external_ip = "0.0.0.0"
inactive_peer_cleanup_interval = 600
log_level = "info"
trace_level = "info"
max_peer_timeout = 900
min_announce_interval = 120
mode = "public"
Expand Down
2 changes: 1 addition & 1 deletion share/default/config/tracker.container.sqlite3.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ db_driver = "Sqlite3"
db_path = "/var/lib/torrust/tracker/database/sqlite3.db"
external_ip = "0.0.0.0"
inactive_peer_cleanup_interval = 600
log_level = "info"
trace_level = "info"
max_peer_timeout = 900
min_announce_interval = 120
mode = "public"
Expand Down
2 changes: 1 addition & 1 deletion share/default/config/tracker.development.sqlite3.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ db_driver = "Sqlite3"
db_path = "./storage/tracker/lib/database/sqlite3.db"
external_ip = "0.0.0.0"
inactive_peer_cleanup_interval = 600
log_level = "info"
trace_level = "info"
max_peer_timeout = 900
min_announce_interval = 120
mode = "public"
Expand Down
Loading

0 comments on commit 9f71c47

Please sign in to comment.