forked from proxmox-mirrors/proxmox
notify: migrate from log
to tracing
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 <g.goller@proxmox.com> Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
This commit is contained in:
parent
212249e009
commit
df6b705f56
@ -18,7 +18,7 @@ const_format.workspace = true
|
|||||||
handlebars = { workspace = true }
|
handlebars = { workspace = true }
|
||||||
http = { workspace = true, optional = true }
|
http = { workspace = true, optional = true }
|
||||||
lettre = { workspace = true, optional = true }
|
lettre = { workspace = true, optional = true }
|
||||||
log.workspace = true
|
tracing.workspace = true
|
||||||
mail-parser = { workspace = true, optional = true }
|
mail-parser = { workspace = true, optional = true }
|
||||||
openssl.workspace = true
|
openssl.workspace = true
|
||||||
percent-encoding = { workspace = true, optional = true }
|
percent-encoding = { workspace = true, optional = true }
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
use std::sync::OnceLock;
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
|
use tracing::warn;
|
||||||
|
|
||||||
use proxmox_schema::{ApiType, ObjectSchema};
|
use proxmox_schema::{ApiType, ObjectSchema};
|
||||||
use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin};
|
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.
|
// This mechanism cleans out left-over entries.
|
||||||
let entries: Vec<GroupConfig> = data.convert_to_typed_array("group").unwrap_or_default();
|
let entries: Vec<GroupConfig> = data.convert_to_typed_array("group").unwrap_or_default();
|
||||||
if !entries.is_empty() {
|
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 {
|
for entry in entries {
|
||||||
@ -157,7 +159,7 @@ pub fn config(raw_config: &str) -> Result<(SectionConfigData, [u8; 32]), Error>
|
|||||||
|
|
||||||
let entries: Vec<FilterConfig> = data.convert_to_typed_array("filter").unwrap_or_default();
|
let entries: Vec<FilterConfig> = data.convert_to_typed_array("filter").unwrap_or_default();
|
||||||
if !entries.is_empty() {
|
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 {
|
for entry in entries {
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
use tracing::error;
|
||||||
|
|
||||||
pub(crate) fn attempt_file_read<P: AsRef<Path>>(path: P) -> Option<String> {
|
pub(crate) fn attempt_file_read<P: AsRef<Path>>(path: P) -> Option<String> {
|
||||||
match proxmox_sys::fs::file_read_optional_string(path) {
|
match proxmox_sys::fs::file_read_optional_string(path) {
|
||||||
Ok(contents) => contents,
|
Ok(contents) => contents,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::error!("{err}");
|
error!("{err}");
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
use serde::Deserialize;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
use serde::Deserialize;
|
||||||
|
use tracing::error;
|
||||||
|
|
||||||
use proxmox_schema::{ObjectSchema, Schema, StringSchema};
|
use proxmox_schema::{ObjectSchema, Schema, StringSchema};
|
||||||
use proxmox_section_config::{SectionConfig, SectionConfigPlugin};
|
use proxmox_section_config::{SectionConfig, SectionConfigPlugin};
|
||||||
|
|
||||||
@ -46,13 +48,13 @@ fn lookup_mail_address(content: &str, username: &str) -> Option<String> {
|
|||||||
match parsed.lookup::<DummyPbsUser>("user", username) {
|
match parsed.lookup::<DummyPbsUser>("user", username) {
|
||||||
Ok(user) => common::normalize_for_return(user.email.as_deref()),
|
Ok(user) => common::normalize_for_return(user.email.as_deref()),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::error!("unable to parse {PBS_USER_CFG_FILENAME}: {err}");
|
error!("unable to parse {PBS_USER_CFG_FILENAME}: {err}");
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::error!("unable to parse {PBS_USER_CFG_FILENAME}: {err}");
|
error!("unable to parse {PBS_USER_CFG_FILENAME}: {err}");
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -336,7 +336,7 @@ impl Endpoint for SmtpEndpoint {
|
|||||||
let header = HeaderValue::new(name, value);
|
let header = HeaderValue::new(name, value);
|
||||||
message.headers_mut().insert_raw(header);
|
message.headers_mut().insert_raw(header);
|
||||||
}
|
}
|
||||||
Err(e) => log::error!("could not set header: {e}"),
|
Err(e) => error!("could not set header: {e}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ use context::context;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
use tracing::{error, info};
|
||||||
|
|
||||||
use proxmox_schema::api;
|
use proxmox_schema::api;
|
||||||
use proxmox_section_config::SectionConfigData;
|
use proxmox_section_config::SectionConfigData;
|
||||||
@ -299,9 +300,7 @@ impl Config {
|
|||||||
if let Some(obj) = value.as_object_mut() {
|
if let Some(obj) = value.as_object_mut() {
|
||||||
obj.insert("origin".to_string(), Value::String("builtin".into()));
|
obj.insert("origin".to_string(), Value::String("builtin".into()));
|
||||||
} else {
|
} else {
|
||||||
log::error!(
|
error!("section config entry is not an object. This should not happen");
|
||||||
"section config entry is not an object. This should not happen"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Entry is built-in, but it has been modified by the user.
|
// Entry is built-in, but it has been modified by the user.
|
||||||
@ -311,9 +310,7 @@ impl Config {
|
|||||||
Value::String("modified-builtin".into()),
|
Value::String("modified-builtin".into()),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
log::error!(
|
error!("section config entry is not an object. This should not happen");
|
||||||
"section config entry is not an object. This should not happen"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -322,7 +319,7 @@ impl Config {
|
|||||||
if let Some(obj) = val.as_object_mut() {
|
if let Some(obj) = val.as_object_mut() {
|
||||||
obj.insert("origin".to_string(), Value::String("builtin".into()));
|
obj.insert("origin".to_string(), Value::String("builtin".into()));
|
||||||
} else {
|
} 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
|
config
|
||||||
.set_data(key, builtin_typename, val)
|
.set_data(key, builtin_typename, val)
|
||||||
@ -356,7 +353,7 @@ impl Config {
|
|||||||
if let Some(obj) = value.as_object_mut() {
|
if let Some(obj) = value.as_object_mut() {
|
||||||
obj.remove("origin");
|
obj.remove("origin");
|
||||||
} else {
|
} 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) {
|
match $config.private_config.sections.get(&config.name) {
|
||||||
Some((section_type_name, private_config)) => {
|
Some((section_type_name, private_config)) => {
|
||||||
if $type_name != section_type_name {
|
if $type_name != section_type_name {
|
||||||
log::error!(
|
error!(
|
||||||
"Could not instantiate endpoint '{name}': \
|
"Could not instantiate endpoint '{name}': \
|
||||||
private config has wrong type",
|
private config has wrong type",
|
||||||
name = config.name
|
name = config.name
|
||||||
@ -411,7 +408,7 @@ macro_rules! parse_endpoints_with_private_config {
|
|||||||
private_config: private_config.clone(),
|
private_config: private_config.clone(),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
None => log::error!(
|
None => error!(
|
||||||
"Could not instantiate endpoint '{name}': \
|
"Could not instantiate endpoint '{name}': \
|
||||||
private config does not exist",
|
private config does not exist",
|
||||||
name = config.name
|
name = config.name
|
||||||
@ -551,21 +548,21 @@ impl Bus {
|
|||||||
|
|
||||||
if endpoint.disabled() {
|
if endpoint.disabled() {
|
||||||
// Skip this target if it is disabled
|
// Skip this target if it is disabled
|
||||||
log::info!("skipping disabled target '{name}'");
|
info!("skipping disabled target '{name}'");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
match endpoint.send(notification) {
|
match endpoint.send(notification) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
log::info!("notified via target `{name}`");
|
info!("notified via target `{name}`");
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// Only log on errors, do not propagate fail to the caller.
|
// 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 {
|
} else {
|
||||||
log::error!("could not notify via target '{target}', it does not exist");
|
error!("could not notify via target '{target}', it does not exist");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ use std::str::FromStr;
|
|||||||
use const_format::concatcp;
|
use const_format::concatcp;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use tracing::{error, info};
|
||||||
|
|
||||||
use proxmox_schema::api_types::{COMMENT_SCHEMA, SAFE_ID_REGEX_STR};
|
use proxmox_schema::api_types::{COMMENT_SCHEMA, SAFE_ID_REGEX_STR};
|
||||||
use proxmox_schema::{api, const_regex, ApiStringFormat, Schema, StringSchema, Updater};
|
use proxmox_schema::{api, const_regex, ApiStringFormat, Schema, StringSchema, Updater};
|
||||||
@ -445,7 +446,7 @@ pub fn check_matches<'a>(
|
|||||||
for matcher in matchers {
|
for matcher in matchers {
|
||||||
if matcher.disable.unwrap_or_default() {
|
if matcher.disable.unwrap_or_default() {
|
||||||
// Skip this matcher if it is disabled
|
// 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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -454,7 +455,7 @@ pub fn check_matches<'a>(
|
|||||||
let t = t.unwrap_or_default();
|
let t = t.unwrap_or_default();
|
||||||
targets.extend(t.iter().map(|s| s.as_str()));
|
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),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ use handlebars::{
|
|||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
use tracing::error;
|
||||||
|
|
||||||
use proxmox_human_byte::HumanByte;
|
use proxmox_human_byte::HumanByte;
|
||||||
use proxmox_time::TimeSpan;
|
use proxmox_time::TimeSpan;
|
||||||
@ -142,7 +143,7 @@ impl ValueRenderFunction {
|
|||||||
ValueRenderFunction::Timestamp => value_to_timestamp(value),
|
ValueRenderFunction::Timestamp => value_to_timestamp(value),
|
||||||
}
|
}
|
||||||
.unwrap_or_else(|| {
|
.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")
|
String::from("ERROR")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user