From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pbs-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9])
	by lore.proxmox.com (Postfix) with ESMTPS id 2B7231FF171
	for <inbox@lore.proxmox.com>; Fri, 16 Aug 2024 12:39:48 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 8383E139E7;
	Fri, 16 Aug 2024 12:40:04 +0200 (CEST)
From: Gabriel Goller <g.goller@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Fri, 16 Aug 2024 12:39:58 +0200
Message-Id: <20240816103958.187644-1-g.goller@proxmox.com>
X-Mailer: git-send-email 2.39.2
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.044 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 T_SCC_BODY_TEXT_LINE    -0.01 -
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [pull.rs, environment.rs]
Subject: [pbs-devel] [PATCH proxmox-backup v2] log: retrieve
 `ReaderEnvironment` debug flag from tracing
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox Backup Server development discussion
 <pbs-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pbs-devel-bounces@lists.proxmox.com
Sender: "pbs-devel" <pbs-devel-bounces@lists.proxmox.com>

Don't hardcode the debug flag but retrieve the currently enabled level
using tracing. This will change the default log-behavior and disable
some logs that have been printed previously. F.e.: the "protocol upgrade
done" message is not visible anymore per default because it is printed
with debug.

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---

Note that this still keeps the behavior of the client controlling the
log-level of the server, except if the server has a minimum log level of
warn.

v2, thanks @Christian:
 - call self.log in self.debug
 - do the same things in ReaderEnvironment

 src/api2/backup/environment.rs | 11 ++++++++---
 src/api2/reader/environment.rs | 11 ++++++++---
 src/server/pull.rs             | 11 +++++++++--
 3 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/src/api2/backup/environment.rs b/src/api2/backup/environment.rs
index 0a7c67b672a3..99d885e2e3c8 100644
--- a/src/api2/backup/environment.rs
+++ b/src/api2/backup/environment.rs
@@ -2,6 +2,7 @@ use anyhow::{bail, format_err, Error};
 use nix::dir::Dir;
 use std::collections::HashMap;
 use std::sync::{Arc, Mutex};
+use tracing::info;
 
 use ::serde::Serialize;
 use serde_json::{json, Value};
@@ -141,7 +142,7 @@ impl BackupEnvironment {
             auth_id,
             worker,
             datastore,
-            debug: false,
+            debug: tracing::enabled!(tracing::Level::DEBUG),
             formatter: JSON_FORMATTER,
             backup_dir,
             last_backup: None,
@@ -687,12 +688,16 @@ impl BackupEnvironment {
     }
 
     pub fn log<S: AsRef<str>>(&self, msg: S) {
-        self.worker.log_message(msg);
+        info!("{}", msg.as_ref());
     }
 
     pub fn debug<S: AsRef<str>>(&self, msg: S) {
         if self.debug {
-            self.worker.log_message(msg);
+            // This is kinda weird, we would like to use tracing::debug! here and automatically
+            // filter it, but self.debug is set from the client-side and the logs are printed on
+            // client and server side. This means that if the client sets the log level to debug,
+            // both server and client need to have 'debug' logs printed.
+            self.log(msg);
         }
     }
 
diff --git a/src/api2/reader/environment.rs b/src/api2/reader/environment.rs
index 602c65e458a3..3b2f06f438fe 100644
--- a/src/api2/reader/environment.rs
+++ b/src/api2/reader/environment.rs
@@ -10,6 +10,7 @@ use pbs_datastore::backup_info::BackupDir;
 use pbs_datastore::DataStore;
 use proxmox_rest_server::formatter::*;
 use proxmox_rest_server::WorkerTask;
+use tracing::info;
 
 /// `RpcEnvironment` implementation for backup reader service
 #[derive(Clone)]
@@ -39,7 +40,7 @@ impl ReaderEnvironment {
             auth_id,
             worker,
             datastore,
-            debug: false,
+            debug: tracing::enabled!(tracing::Level::DEBUG),
             formatter: JSON_FORMATTER,
             backup_dir,
             allowed_chunks: Arc::new(RwLock::new(HashSet::new())),
@@ -47,12 +48,16 @@ impl ReaderEnvironment {
     }
 
     pub fn log<S: AsRef<str>>(&self, msg: S) {
-        self.worker.log_message(msg);
+        info!("{}", msg.as_ref());
     }
 
     pub fn debug<S: AsRef<str>>(&self, msg: S) {
         if self.debug {
-            self.worker.log_message(msg);
+            // This is kinda weird, we would like to use tracing::debug! here and automatically
+            // filter it, but self.debug is set from the client-side and the logs are printed on
+            // client and server side. This means that if the client sets the log level to debug,
+            // both server and client need to have 'debug' logs printed.
+            self.log(msg);
         }
     }
 
diff --git a/src/server/pull.rs b/src/server/pull.rs
index 823515e9ab02..de1bb5d5f6af 100644
--- a/src/server/pull.rs
+++ b/src/server/pull.rs
@@ -278,8 +278,15 @@ impl PullSource for RemoteSource {
         ns: &BackupNamespace,
         dir: &BackupDir,
     ) -> Result<Arc<dyn PullReader>, Error> {
-        let backup_reader =
-            BackupReader::start(&self.client, None, self.repo.store(), ns, dir, true).await?;
+        let backup_reader = BackupReader::start(
+            &self.client,
+            None,
+            self.repo.store(),
+            ns,
+            dir,
+            tracing::enabled!(tracing::Level::DEBUG),
+        )
+        .await?;
         Ok(Arc::new(RemoteReader {
             backup_reader,
             dir: dir.clone(),
-- 
2.39.2



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel