Skip to content

Commit

Permalink
tracing: qualify use of tracing macros
Browse files Browse the repository at this point in the history
  • Loading branch information
da2ce7 committed Aug 25, 2024
1 parent 06857d2 commit e4aa1db
Show file tree
Hide file tree
Showing 31 changed files with 92 additions and 125 deletions.
4 changes: 1 addition & 3 deletions packages/located-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ use std::error::Error;
use std::panic::Location;
use std::sync::Arc;

use tracing::debug;

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

/// A generic wrapper around an error.
Expand Down Expand Up @@ -94,7 +92,7 @@ where
source: Arc::new(self.0),
location: Box::new(*std::panic::Location::caller()),
};
debug!("{e}");
tracing::debug!("{e}");
e
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use std::sync::Arc;

use tokio::task::JoinHandle;
use torrust_tracker_configuration::Configuration;
use tracing::{info, warn};

use crate::bootstrap::jobs::{health_check_api, http_tracker, torrent_cleanup, tracker_apis, udp_tracker};
use crate::servers::registar::Registar;
Expand All @@ -42,7 +41,7 @@ pub async fn start(config: &Configuration, tracker: Arc<core::Tracker>) -> Vec<J
&& (config.udp_trackers.is_none() || config.udp_trackers.as_ref().map_or(true, std::vec::Vec::is_empty))
&& (config.http_trackers.is_none() || config.http_trackers.as_ref().map_or(true, std::vec::Vec::is_empty))
{
warn!("No services enabled in configuration");
tracing::warn!("No services enabled in configuration");
}

let mut jobs: Vec<JoinHandle<()>> = Vec::new();
Expand All @@ -69,7 +68,7 @@ pub async fn start(config: &Configuration, tracker: Arc<core::Tracker>) -> Vec<J
if let Some(udp_trackers) = &config.udp_trackers {
for udp_tracker_config in udp_trackers {
if tracker.is_private() {
warn!(
tracing::warn!(
"Could not start UDP tracker on: {} while in private mode. UDP is not safe for private trackers!",
udp_tracker_config.bind_address
);
Expand All @@ -78,7 +77,7 @@ pub async fn start(config: &Configuration, tracker: Arc<core::Tracker>) -> Vec<J
}
}
} else {
info!("No UDP blocks in configuration");
tracing::info!("No UDP blocks in configuration");
}

// Start the HTTP blocks
Expand All @@ -96,7 +95,7 @@ pub async fn start(config: &Configuration, tracker: Arc<core::Tracker>) -> Vec<J
};
}
} else {
info!("No HTTP blocks in configuration");
tracing::info!("No HTTP blocks in configuration");
}

// Start HTTP API
Expand All @@ -112,7 +111,7 @@ pub async fn start(config: &Configuration, tracker: Arc<core::Tracker>) -> Vec<J
jobs.push(job);
};
} else {
info!("No API block in configuration");
tracing::info!("No API block in configuration");
}

// Start runners to remove torrents without peers, every interval
Expand Down
3 changes: 1 addition & 2 deletions src/bootstrap/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use std::sync::Arc;
use torrust_tracker_clock::static_time;
use torrust_tracker_configuration::validator::Validator;
use torrust_tracker_configuration::Configuration;
use tracing::info;

use super::config::initialize_configuration;
use crate::bootstrap;
Expand All @@ -39,7 +38,7 @@ pub fn setup() -> (Configuration, Arc<Tracker>) {

let tracker = initialize_with_configuration(&configuration);

info!("Configuration:\n{}", configuration.clone().mask_secrets().to_json());
tracing::info!("Configuration:\n{}", configuration.clone().mask_secrets().to_json());

(configuration, tracker)
}
Expand Down
7 changes: 3 additions & 4 deletions src/bootstrap/jobs/health_check_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use tokio::sync::oneshot;
use tokio::task::JoinHandle;
use torrust_tracker_configuration::HealthCheckApi;
use tracing::info;

use super::Started;
use crate::servers::health_check_api::{server, HEALTH_CHECK_API_LOG_TARGET};
Expand Down Expand Up @@ -45,18 +44,18 @@ pub async fn start_job(config: &HealthCheckApi, register: ServiceRegistry) -> Jo

// Run the API server
let join_handle = tokio::spawn(async move {
info!(target: HEALTH_CHECK_API_LOG_TARGET, "Starting on: {protocol}://{}", bind_addr);
tracing::info!(target: HEALTH_CHECK_API_LOG_TARGET, "Starting on: {protocol}://{}", bind_addr);

let handle = server::start(bind_addr, tx_start, rx_halt, register);

if let Ok(()) = handle.await {
info!(target: HEALTH_CHECK_API_LOG_TARGET, "Stopped server running on: {protocol}://{}", bind_addr);
tracing::info!(target: HEALTH_CHECK_API_LOG_TARGET, "Stopped server running on: {protocol}://{}", bind_addr);
}
});

// Wait until the server sends the started message
match rx_start.await {
Ok(msg) => info!(target: HEALTH_CHECK_API_LOG_TARGET, "{STARTED_ON}: {protocol}://{}", msg.address),
Ok(msg) => tracing::info!(target: HEALTH_CHECK_API_LOG_TARGET, "{STARTED_ON}: {protocol}://{}", msg.address),
Err(e) => panic!("the Health Check API server was dropped: {e}"),
}

Expand Down
5 changes: 2 additions & 3 deletions src/bootstrap/jobs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ pub async fn make_rust_tls(opt_tsl_config: &Option<TslConfig>) -> Option<Result<
}));
}

info!("Using https: cert path: {cert}.");
info!("Using https: key path: {key}.");
tracing::info!("Using https: cert path: {cert}.");
tracing::info!("Using https: key path: {key}.");

Some(
RustlsConfig::from_pem_file(cert, key)
Expand Down Expand Up @@ -89,7 +89,6 @@ use axum_server::tls_rustls::RustlsConfig;
use thiserror::Error;
use torrust_tracker_configuration::TslConfig;
use torrust_tracker_located_error::{DynError, LocatedError};
use tracing::info;

/// Error returned by the Bootstrap Process.
#[derive(Error, Debug)]
Expand Down
7 changes: 3 additions & 4 deletions src/bootstrap/jobs/torrent_cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use std::sync::Arc;
use chrono::Utc;
use tokio::task::JoinHandle;
use torrust_tracker_configuration::Core;
use tracing::info;

use crate::core;

Expand All @@ -37,15 +36,15 @@ pub fn start_job(config: &Core, tracker: &Arc<core::Tracker>) -> JoinHandle<()>
loop {
tokio::select! {
_ = tokio::signal::ctrl_c() => {
info!("Stopping torrent cleanup job..");
tracing::info!("Stopping torrent cleanup job..");
break;
}
_ = interval.tick() => {
if let Some(tracker) = weak_tracker.upgrade() {
let start_time = Utc::now().time();
info!("Cleaning up torrents..");
tracing::info!("Cleaning up torrents..");
tracker.cleanup_torrents();
info!("Cleaned up torrents in: {}ms", (Utc::now().time() - start_time).num_milliseconds());
tracing::info!("Cleaned up torrents in: {}ms", (Utc::now().time() - start_time).num_milliseconds());
} else {
break;
}
Expand Down
7 changes: 3 additions & 4 deletions src/bootstrap/jobs/udp_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use std::sync::Arc;

use tokio::task::JoinHandle;
use torrust_tracker_configuration::UdpTracker;
use tracing::debug;

use crate::core;
use crate::servers::registar::ServiceRegistrationForm;
Expand All @@ -37,8 +36,8 @@ pub async fn start_job(config: &UdpTracker, tracker: Arc<core::Tracker>, form: S
.expect("it should be able to start the udp tracker");

tokio::spawn(async move {
debug!(target: UDP_TRACKER_LOG_TARGET, "Wait for launcher (UDP service) to finish ...");
debug!(target: UDP_TRACKER_LOG_TARGET, "Is halt channel closed before waiting?: {}", server.state.halt_task.is_closed());
tracing::debug!(target: UDP_TRACKER_LOG_TARGET, "Wait for launcher (UDP service) to finish ...");
tracing::debug!(target: UDP_TRACKER_LOG_TARGET, "Is halt channel closed before waiting?: {}", server.state.halt_task.is_closed());

assert!(
!server.state.halt_task.is_closed(),
Expand All @@ -51,6 +50,6 @@ pub async fn start_job(config: &UdpTracker, tracker: Arc<core::Tracker>, form: S
.await
.expect("it should be able to join to the udp tracker task");

debug!(target: UDP_TRACKER_LOG_TARGET, "Is halt channel closed after finishing the server?: {}", server.state.halt_task.is_closed());
tracing::debug!(target: UDP_TRACKER_LOG_TARGET, "Is halt channel closed after finishing the server?: {}", server.state.halt_task.is_closed());
})
}
3 changes: 1 addition & 2 deletions src/bootstrap/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use std::sync::Once;

use torrust_tracker_configuration::{Configuration, Threshold};
use tracing::info;
use tracing::level_filters::LevelFilter;

static INIT: Once = Once::new();
Expand Down Expand Up @@ -54,7 +53,7 @@ fn tracing_stdout_init(filter: LevelFilter, style: &TraceStyle) {
TraceStyle::Json => builder.json().init(),
};

info!("Logging initialized");
tracing::info!("Logging initialized");
}

#[derive(Debug)]
Expand Down
8 changes: 3 additions & 5 deletions src/console/ci/e2e/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use std::process::{Command, Output};
use std::thread::sleep;
use std::time::{Duration, Instant};

use tracing::{debug, info};

/// Docker command wrapper.
pub struct Docker {}

Expand All @@ -20,7 +18,7 @@ impl Drop for RunningContainer {
/// Ensures that the temporary container is stopped when the struct goes out
/// of scope.
fn drop(&mut self) {
info!("Dropping running container: {}", self.name);
tracing::info!("Dropping running container: {}", self.name);
if Docker::is_container_running(&self.name) {
let _unused = Docker::stop(self);
}
Expand Down Expand Up @@ -89,7 +87,7 @@ impl Docker {

let args = [initial_args, env_var_args, port_args, [image.to_string()].to_vec()].concat();

debug!("Docker run args: {:?}", args);
tracing::debug!("Docker run args: {:?}", args);

let output = Command::new("docker").args(args).output()?;

Expand Down Expand Up @@ -176,7 +174,7 @@ impl Docker {

let output_str = String::from_utf8_lossy(&output.stdout);

info!("Waiting until container is healthy: {:?}", output_str);
tracing::info!("Waiting until container is healthy: {:?}", output_str);

if output_str.contains("(healthy)") {
return true;
Expand Down
13 changes: 6 additions & 7 deletions src/console/ci/e2e/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use std::path::PathBuf;

use anyhow::Context;
use clap::Parser;
use tracing::info;
use tracing::level_filters::LevelFilter;

use super::tracker_container::TrackerContainer;
Expand Down Expand Up @@ -68,7 +67,7 @@ pub fn run() -> anyhow::Result<()> {

let tracker_config = load_tracker_configuration(&args)?;

info!("tracker config:\n{tracker_config}");
tracing::info!("tracker config:\n{tracker_config}");

let mut tracker_container = TrackerContainer::new(CONTAINER_IMAGE, CONTAINER_NAME_PREFIX);

Expand All @@ -91,7 +90,7 @@ pub fn run() -> anyhow::Result<()> {

let running_services = tracker_container.running_services();

info!(
tracing::info!(
"Running services:\n {}",
serde_json::to_string_pretty(&running_services).expect("running services to be serializable to JSON")
);
Expand All @@ -110,27 +109,27 @@ pub fn run() -> anyhow::Result<()> {

tracker_container.remove();

info!("Tracker container final state:\n{:#?}", tracker_container);
tracing::info!("Tracker container final state:\n{:#?}", tracker_container);

Ok(())
}

fn tracing_stdout_init(filter: LevelFilter) {
tracing_subscriber::fmt().with_max_level(filter).init();
info!("Logging initialized");
tracing::info!("Logging initialized");
}

fn load_tracker_configuration(args: &Args) -> anyhow::Result<String> {
match (args.config_toml_path.clone(), args.config_toml.clone()) {
(Some(config_path), _) => {
info!(
tracing::info!(
"Reading tracker configuration from file: {} ...",
config_path.to_string_lossy()
);
load_config_from_file(&config_path)
}
(_, Some(config_content)) => {
info!("Reading tracker configuration from env var ...");
tracing::info!("Reading tracker configuration from env var ...");
Ok(config_content)
}
_ => Err(anyhow::anyhow!("No configuration provided")),
Expand Down
6 changes: 2 additions & 4 deletions src/console/ci/e2e/tracker_checker.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use std::io;
use std::process::Command;

use tracing::info;

/// Runs the Tracker Checker.
///
/// # Errors
///
/// Will return an error if the Tracker Checker fails.
pub fn run(config_content: &str) -> io::Result<()> {
info!("Running Tracker Checker: TORRUST_CHECKER_CONFIG=[config] cargo run --bin tracker_checker");
info!("Tracker Checker config:\n{config_content}");
tracing::info!("Running Tracker Checker: TORRUST_CHECKER_CONFIG=[config] cargo run --bin tracker_checker");
tracing::info!("Tracker Checker config:\n{config_content}");

let status = Command::new("cargo")
.env("TORRUST_CHECKER_CONFIG", config_content)
Expand Down
Loading

0 comments on commit e4aa1db

Please sign in to comment.