secra_logger/
field_normalization.rs1use std::collections::HashMap;
6use tracing_subscriber::layer::Layer;
7use tracing::Event;
8
9#[allow(dead_code)]
13pub struct FieldNormalizationLayer {
14 mappings: HashMap<String, String>,
15 enabled: bool,
16}
17
18impl FieldNormalizationLayer {
19 #[allow(dead_code)]
21 pub fn new(mappings: HashMap<String, String>, enabled: bool) -> Self {
22 Self {
23 mappings,
24 enabled,
25 }
26 }
27}
28
29impl<S> Layer<S> for FieldNormalizationLayer
30where
31 S: tracing::Subscriber + for<'a> tracing_subscriber::registry::LookupSpan<'a>,
32{
33 fn on_event(&self, _event: &Event<'_>, _ctx: tracing_subscriber::layer::Context<'_, S>) {
34 if !self.enabled {
35 return;
36 }
37
38 }
43}
44
45#[allow(dead_code)]
54pub fn normalize_field_name(name: &str) -> String {
55 if name.contains('.') {
57 return name.to_string();
58 }
59
60 let mut result = String::new();
63 let mut chars = name.chars().peekable();
64
65 while let Some(ch) = chars.next() {
66 if ch.is_uppercase() && !result.is_empty() {
67 result.push('.');
68 result.push(ch.to_lowercase().next().unwrap());
69 } else {
70 result.push(ch.to_lowercase().next().unwrap());
71 }
72 }
73
74 result
75}