Skip to content

Commit bb8b2ad

Browse files
committed
Merge torrust#919: Fix: clients output in JSON should not include logging
2518c54 fix: [torrust#917] clients output in JSON should not include logging (Jose Celano) Pull request description: The console clients' output should not include logging info when the output is JSON. IT fixes this behavior: Command: ```s $ cargo run --bin udp_tracker_client announce 144.126.245.19:6969 9c38422213e30bff212b30c360d26f9a02136422 Finished `dev` profile [optimized + debuginfo] target(s) in 0.09s Running `target/debug/udp_tracker_client announce '144.126.245.19:6969' 9c38422213e30bff212b30c360d26f9a02136422` Output: ```s 2024-06-26T07:46:10.051490Z INFO torrust_tracker::console::clients::udp::app: logging initialized. { "AnnounceIpv4": { "transaction_id": -888840697, "announce_interval": 300, "leechers": 0, "seeders": 1, "peers": [] } } ``` The line `2024-06-26T07:46:10.051490Z INFO torrust_tracker::console::clients::udp::app: logging initialized.` or any other lines should not be included. I will open a discussion about how to deal with logging in console clients. ACKs for top commit: josecelano: ACK 2518c54 Tree-SHA512: 9882e3b1701ce13549c8dd6c7a5a515bbdd8e3206eb560424c2e205962d2c50314d03f2ae19eed303aea1277d49b9a669a5d9f24701ac7631608850a0290667f
2 parents eb9f997 + 2518c54 commit bb8b2ad

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

src/console/clients/checker/app.rs

+46-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,56 @@
1212
//! ```text
1313
//! TORRUST_CHECKER_CONFIG=$(cat "./share/default/config/tracker_checker.json") cargo run --bin tracker_checker
1414
//! ```
15+
//!
16+
//! Another real example to test the Torrust demo tracker:
17+
//!
18+
//! ```text
19+
//! TORRUST_CHECKER_CONFIG='{
20+
//! "udp_trackers": ["144.126.245.19:6969"],
21+
//! "http_trackers": ["https://tracker.torrust-demo.com"],
22+
//! "health_checks": ["https://tracker.torrust-demo.com/api/health_check"]
23+
//! }' cargo run --bin tracker_checker
24+
//! ```
25+
//!
26+
//! The output should be something like the following:
27+
//!
28+
//! ```json
29+
//! {
30+
//! "udp_trackers": [
31+
//! {
32+
//! "url": "144.126.245.19:6969",
33+
//! "status": {
34+
//! "code": "ok",
35+
//! "message": ""
36+
//! }
37+
//! }
38+
//! ],
39+
//! "http_trackers": [
40+
//! {
41+
//! "url": "https://tracker.torrust-demo.com/",
42+
//! "status": {
43+
//! "code": "ok",
44+
//! "message": ""
45+
//! }
46+
//! }
47+
//! ],
48+
//! "health_checks": [
49+
//! {
50+
//! "url": "https://tracker.torrust-demo.com/api/health_check",
51+
//! "status": {
52+
//! "code": "ok",
53+
//! "message": ""
54+
//! }
55+
//! }
56+
//! ]
57+
//! }
58+
//! ```
1559
use std::path::PathBuf;
1660
use std::sync::Arc;
1761

1862
use anyhow::{Context, Result};
1963
use clap::Parser;
20-
use tracing::info;
64+
use tracing::debug;
2165
use tracing::level_filters::LevelFilter;
2266

2367
use super::config::Configuration;
@@ -59,7 +103,7 @@ pub async fn run() -> Result<Vec<CheckResult>> {
59103

60104
fn tracing_stdout_init(filter: LevelFilter) {
61105
tracing_subscriber::fmt().with_max_level(filter).init();
62-
info!("logging initialized.");
106+
debug!("logging initialized.");
63107
}
64108

65109
fn setup_config(args: Args) -> Result<Configuration> {

src/console/clients/udp/app.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ use anyhow::Context;
6363
use aquatic_udp_protocol::{Port, Response, TransactionId};
6464
use clap::{Parser, Subcommand};
6565
use torrust_tracker_primitives::info_hash::InfoHash as TorrustInfoHash;
66+
use tracing::debug;
6667
use tracing::level_filters::LevelFilter;
67-
use tracing::{debug, info};
6868
use url::Url;
6969

7070
use crate::console::clients::udp::checker;
@@ -128,7 +128,7 @@ pub async fn run() -> anyhow::Result<()> {
128128

129129
fn tracing_stdout_init(filter: LevelFilter) {
130130
tracing_subscriber::fmt().with_max_level(filter).init();
131-
info!("logging initialized.");
131+
debug!("logging initialized.");
132132
}
133133

134134
async fn handle_announce(tracker_socket_addr: &SocketAddr, info_hash: &TorrustInfoHash) -> anyhow::Result<Response> {

0 commit comments

Comments
 (0)