-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathotlp_log.rs
More file actions
77 lines (64 loc) · 1.9 KB
/
otlp_log.rs
File metadata and controls
77 lines (64 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! OTLP Log Subscriber Settings.
use std::ops::Deref;
use super::{Build, Settings, SettingsBuilder};
#[derive(Debug, Default, PartialEq)]
pub struct OtlpLogSettings {
pub common_settings: Settings,
}
impl Deref for OtlpLogSettings {
type Target = Settings;
fn deref(&self) -> &Self::Target {
&self.common_settings
}
}
pub struct OtlpLogSettingsBuilder {
pub(crate) common_settings: Settings,
}
impl OtlpLogSettingsBuilder {
pub fn build(self) -> OtlpLogSettings {
OtlpLogSettings {
common_settings: self.common_settings,
}
}
}
/// This implementation is used to turn the common settings builder into the OTLP log specific
/// settings builder via the [`SettingsBuilder::otlp_log_settings_builder`] function.
impl From<SettingsBuilder> for OtlpLogSettingsBuilder {
fn from(value: SettingsBuilder) -> Self {
Self {
common_settings: value.build(),
}
}
}
/// This implementation is used to build OTLP log settings from common settings without
/// specifying OTLP log specific settings.
impl Build<OtlpLogSettings> for SettingsBuilder {
fn build(self) -> OtlpLogSettings {
OtlpLogSettings {
common_settings: self.build(),
// ..Default::default()
}
}
}
#[cfg(test)]
mod test {
use tracing::level_filters::LevelFilter;
use super::*;
#[test]
fn builds_settings() {
let expected = OtlpLogSettings {
common_settings: Settings {
environment_variable: "hello",
default_level: LevelFilter::DEBUG,
enabled: true,
},
};
let result = Settings::builder()
.with_environment_variable("hello")
.with_default_level(LevelFilter::DEBUG)
.enabled(true)
.otlp_log_settings_builder()
.build();
assert_eq!(expected, result);
}
}