improve debug formatting of config

This commit is contained in:
Chris Beck
2025-12-07 00:02:45 -07:00
parent 35f8ff766d
commit 13b6490525
2 changed files with 41 additions and 4 deletions
+21 -3
View File
@@ -15,10 +15,16 @@ use std::str::FromStr;
use tracing::{debug, info, warn}; use tracing::{debug, info, warn};
/// A validated Signal UUID in the format `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`. /// A validated Signal UUID in the format `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Deserialize)] #[derive(Clone, PartialEq, Eq, Hash, Deserialize)]
#[serde(try_from = "String")] #[serde(try_from = "String")]
pub struct Uuid(String); pub struct Uuid(String);
impl fmt::Debug for Uuid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.0, f)
}
}
impl FromStr for Uuid { impl FromStr for Uuid {
type Err = String; type Err = String;
@@ -98,10 +104,16 @@ impl fmt::Display for Uuid {
} }
/// A validated Signal safety number (60 digits, optionally separated by whitespace). /// A validated Signal safety number (60 digits, optionally separated by whitespace).
#[derive(Clone, Debug, PartialEq, Eq, Hash, Deserialize)] #[derive(Clone, PartialEq, Eq, Hash, Deserialize)]
#[serde(try_from = "String")] #[serde(try_from = "String")]
pub struct SafetyNumber(String); pub struct SafetyNumber(String);
impl fmt::Debug for SafetyNumber {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.0, f)
}
}
impl FromStr for SafetyNumber { impl FromStr for SafetyNumber {
type Err = String; type Err = String;
@@ -175,11 +187,17 @@ impl fmt::Display for SafetyNumber {
/// Can be deserialized from either: /// Can be deserialized from either:
/// - A map of UUID -> safety numbers: `{"uuid1": ["12345..."], "uuid2": []}` /// - A map of UUID -> safety numbers: `{"uuid1": ["12345..."], "uuid2": []}`
/// - A sequence of UUIDs (no safety numbers): `["uuid1", "uuid2"]` /// - A sequence of UUIDs (no safety numbers): `["uuid1", "uuid2"]`
#[derive(Clone, Debug, Default)] #[derive(Clone, Default)]
pub struct SignalTrustSet { pub struct SignalTrustSet {
map: HashMap<Uuid, Vec<SafetyNumber>>, map: HashMap<Uuid, Vec<SafetyNumber>>,
} }
impl fmt::Debug for SignalTrustSet {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.map, f)
}
}
impl SignalTrustSet { impl SignalTrustSet {
/// Create an empty container. /// Create an empty container.
pub fn new() -> Self { pub fn new() -> Self {
+20 -1
View File
@@ -269,7 +269,7 @@ impl Origin {
/// Filter criteria for matching log messages. /// Filter criteria for matching log messages.
/// ///
/// All non-empty fields must match for the filter to pass. /// All non-empty fields must match for the filter to pass.
#[derive(Clone, Debug, Default, Deserialize)] #[derive(Clone, Default, Deserialize)]
pub struct LogFilter { pub struct LogFilter {
/// If non-empty, the message must contain this substring. /// If non-empty, the message must contain this substring.
#[serde(default)] #[serde(default)]
@@ -285,6 +285,25 @@ pub struct LogFilter {
pub line_equals: String, pub line_equals: String,
} }
impl std::fmt::Debug for LogFilter {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut s = f.debug_struct("LogFilter");
if !self.msg_contains.is_empty() {
s.field("msg_contains", &self.msg_contains);
}
if !self.module_equals.is_empty() {
s.field("module_equals", &self.module_equals);
}
if !self.file_equals.is_empty() {
s.field("file_equals", &self.file_equals);
}
if !self.line_equals.is_empty() {
s.field("line_equals", &self.line_equals);
}
s.finish()
}
}
impl LogFilter { impl LogFilter {
/// Check if a log message matches this filter. /// Check if a log message matches this filter.
/// ///