log: retrieve ReaderEnvironment debug flag from tracing

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>
This commit is contained in:
Gabriel Goller 2024-08-16 12:39:58 +02:00 committed by Wolfgang Bumiller
parent 631b09b2eb
commit baacc3f2de
3 changed files with 25 additions and 8 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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(),