From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 85B621FF163 for ; Thu, 5 Dec 2024 11:18:29 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5CD841769D; Thu, 5 Dec 2024 11:18:29 +0100 (CET) From: Gabriel Goller To: pbs-devel@lists.proxmox.com Date: Thu, 5 Dec 2024 11:18:20 +0100 Message-Id: <20241205101820.208631-1-g.goller@proxmox.com> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.086 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 PROLO_LEO1 0.1 Meta Catches all Leo drug variations so far SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH] notify: migrate from `log` to `tracing` X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Cc: Lukas Wagner Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" Migrated from `log` to `tracing`. Imported `tracing` only as it has a smaller footprint (and less dependencies) than `proxmox_log`. Signed-off-by: Gabriel Goller --- proxmox-notify/Cargo.toml | 2 +- proxmox-notify/src/config.rs | 6 ++++-- proxmox-notify/src/context/common.rs | 4 +++- proxmox-notify/src/context/pbs.rs | 8 +++++--- proxmox-notify/src/endpoints/smtp.rs | 2 +- proxmox-notify/src/lib.rs | 25 +++++++++++-------------- proxmox-notify/src/matcher.rs | 5 +++-- proxmox-notify/src/renderer/mod.rs | 3 ++- 8 files changed, 30 insertions(+), 25 deletions(-) diff --git a/proxmox-notify/Cargo.toml b/proxmox-notify/Cargo.toml index 725bd21070fb..5c700ca88fc9 100644 --- a/proxmox-notify/Cargo.toml +++ b/proxmox-notify/Cargo.toml @@ -18,7 +18,7 @@ const_format.workspace = true handlebars = { workspace = true } http = { workspace = true, optional = true } lettre = { workspace = true, optional = true } -log.workspace = true +tracing.workspace = true mail-parser = { workspace = true, optional = true } openssl.workspace = true percent-encoding = { workspace = true, optional = true } diff --git a/proxmox-notify/src/config.rs b/proxmox-notify/src/config.rs index 4d0b53f7aaf1..791e0b5fa6af 100644 --- a/proxmox-notify/src/config.rs +++ b/proxmox-notify/src/config.rs @@ -1,5 +1,7 @@ use std::sync::OnceLock; +use tracing::warn; + use proxmox_schema::{ApiType, ObjectSchema}; use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; @@ -148,7 +150,7 @@ pub fn config(raw_config: &str) -> Result<(SectionConfigData, [u8; 32]), Error> // This mechanism cleans out left-over entries. let entries: Vec = data.convert_to_typed_array("group").unwrap_or_default(); if !entries.is_empty() { - log::warn!("clearing left-over 'group' entries from notifications.cfg"); + warn!("clearing left-over 'group' entries from notifications.cfg"); } for entry in entries { @@ -157,7 +159,7 @@ pub fn config(raw_config: &str) -> Result<(SectionConfigData, [u8; 32]), Error> let entries: Vec = data.convert_to_typed_array("filter").unwrap_or_default(); if !entries.is_empty() { - log::warn!("clearing left-over 'filter' entries from notifications.cfg"); + warn!("clearing left-over 'filter' entries from notifications.cfg"); } for entry in entries { diff --git a/proxmox-notify/src/context/common.rs b/proxmox-notify/src/context/common.rs index 7580bd1a318b..88bacf527f5c 100644 --- a/proxmox-notify/src/context/common.rs +++ b/proxmox-notify/src/context/common.rs @@ -1,10 +1,12 @@ use std::path::Path; +use tracing::error; + pub(crate) fn attempt_file_read>(path: P) -> Option { match proxmox_sys::fs::file_read_optional_string(path) { Ok(contents) => contents, Err(err) => { - log::error!("{err}"); + error!("{err}"); None } } diff --git a/proxmox-notify/src/context/pbs.rs b/proxmox-notify/src/context/pbs.rs index 09c555e424cb..cd1176465543 100644 --- a/proxmox-notify/src/context/pbs.rs +++ b/proxmox-notify/src/context/pbs.rs @@ -1,6 +1,8 @@ -use serde::Deserialize; use std::path::Path; +use serde::Deserialize; +use tracing::error; + use proxmox_schema::{ObjectSchema, Schema, StringSchema}; use proxmox_section_config::{SectionConfig, SectionConfigPlugin}; @@ -46,13 +48,13 @@ fn lookup_mail_address(content: &str, username: &str) -> Option { match parsed.lookup::("user", username) { Ok(user) => common::normalize_for_return(user.email.as_deref()), Err(err) => { - log::error!("unable to parse {PBS_USER_CFG_FILENAME}: {err}"); + error!("unable to parse {PBS_USER_CFG_FILENAME}: {err}"); None } } } Err(err) => { - log::error!("unable to parse {PBS_USER_CFG_FILENAME}: {err}"); + error!("unable to parse {PBS_USER_CFG_FILENAME}: {err}"); None } } diff --git a/proxmox-notify/src/endpoints/smtp.rs b/proxmox-notify/src/endpoints/smtp.rs index 973f7fadf2b1..6bb2d2d0c3e7 100644 --- a/proxmox-notify/src/endpoints/smtp.rs +++ b/proxmox-notify/src/endpoints/smtp.rs @@ -336,7 +336,7 @@ impl Endpoint for SmtpEndpoint { let header = HeaderValue::new(name, value); message.headers_mut().insert_raw(header); } - Err(e) => log::error!("could not set header: {e}"), + Err(e) => error!("could not set header: {e}"), } } } diff --git a/proxmox-notify/src/lib.rs b/proxmox-notify/src/lib.rs index 12f3866b535d..12e59474850b 100644 --- a/proxmox-notify/src/lib.rs +++ b/proxmox-notify/src/lib.rs @@ -9,6 +9,7 @@ use context::context; use serde::{Deserialize, Serialize}; use serde_json::json; use serde_json::Value; +use tracing::{error, info}; use proxmox_schema::api; use proxmox_section_config::SectionConfigData; @@ -299,9 +300,7 @@ impl Config { if let Some(obj) = value.as_object_mut() { obj.insert("origin".to_string(), Value::String("builtin".into())); } else { - log::error!( - "section config entry is not an object. This should not happen" - ); + error!("section config entry is not an object. This should not happen"); } } else { // Entry is built-in, but it has been modified by the user. @@ -311,9 +310,7 @@ impl Config { Value::String("modified-builtin".into()), ); } else { - log::error!( - "section config entry is not an object. This should not happen" - ); + error!("section config entry is not an object. This should not happen"); } } } else { @@ -322,7 +319,7 @@ impl Config { if let Some(obj) = val.as_object_mut() { obj.insert("origin".to_string(), Value::String("builtin".into())); } else { - log::error!("section config entry is not an object. This should not happen"); + error!("section config entry is not an object. This should not happen"); } config .set_data(key, builtin_typename, val) @@ -356,7 +353,7 @@ impl Config { if let Some(obj) = value.as_object_mut() { obj.remove("origin"); } else { - log::error!("section config entry is not an object. This should not happen"); + error!("section config entry is not an object. This should not happen"); } } @@ -397,7 +394,7 @@ macro_rules! parse_endpoints_with_private_config { match $config.private_config.sections.get(&config.name) { Some((section_type_name, private_config)) => { if $type_name != section_type_name { - log::error!( + error!( "Could not instantiate endpoint '{name}': \ private config has wrong type", name = config.name @@ -411,7 +408,7 @@ macro_rules! parse_endpoints_with_private_config { private_config: private_config.clone(), })); } - None => log::error!( + None => error!( "Could not instantiate endpoint '{name}': \ private config does not exist", name = config.name @@ -551,21 +548,21 @@ impl Bus { if endpoint.disabled() { // Skip this target if it is disabled - log::info!("skipping disabled target '{name}'"); + info!("skipping disabled target '{name}'"); continue; } match endpoint.send(notification) { Ok(_) => { - log::info!("notified via target `{name}`"); + info!("notified via target `{name}`"); } Err(e) => { // Only log on errors, do not propagate fail to the caller. - log::error!("could not notify via target `{name}`: {e}"); + error!("could not notify via target `{name}`: {e}"); } } } else { - log::error!("could not notify via target '{target}', it does not exist"); + error!("could not notify via target '{target}', it does not exist"); } } } diff --git a/proxmox-notify/src/matcher.rs b/proxmox-notify/src/matcher.rs index 7fb2c9b18b7c..083c2dbda5d5 100644 --- a/proxmox-notify/src/matcher.rs +++ b/proxmox-notify/src/matcher.rs @@ -6,6 +6,7 @@ use std::str::FromStr; use const_format::concatcp; use regex::Regex; use serde::{Deserialize, Serialize}; +use tracing::{error, info}; use proxmox_schema::api_types::{COMMENT_SCHEMA, SAFE_ID_REGEX_STR}; use proxmox_schema::{api, const_regex, ApiStringFormat, Schema, StringSchema, Updater}; @@ -445,7 +446,7 @@ pub fn check_matches<'a>( for matcher in matchers { if matcher.disable.unwrap_or_default() { // Skip this matcher if it is disabled - log::info!("skipping disabled matcher '{name}'", name = matcher.name); + info!("skipping disabled matcher '{name}'", name = matcher.name); continue; } @@ -454,7 +455,7 @@ pub fn check_matches<'a>( let t = t.unwrap_or_default(); targets.extend(t.iter().map(|s| s.as_str())); } - Err(err) => log::error!("matcher '{matcher}' failed: {err}", matcher = matcher.name), + Err(err) => error!("matcher '{matcher}' failed: {err}", matcher = matcher.name), } } diff --git a/proxmox-notify/src/renderer/mod.rs b/proxmox-notify/src/renderer/mod.rs index 393cbbf2775c..e058ea2218b0 100644 --- a/proxmox-notify/src/renderer/mod.rs +++ b/proxmox-notify/src/renderer/mod.rs @@ -8,6 +8,7 @@ use handlebars::{ }; use serde::{Deserialize, Serialize}; use serde_json::Value; +use tracing::error; use proxmox_human_byte::HumanByte; use proxmox_time::TimeSpan; @@ -142,7 +143,7 @@ impl ValueRenderFunction { ValueRenderFunction::Timestamp => value_to_timestamp(value), } .unwrap_or_else(|| { - log::error!("could not render value {value} with renderer {self:?}"); + error!("could not render value {value} with renderer {self:?}"); String::from("ERROR") }) } -- 2.39.5 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel