Skip to content

Commit 5de6ed4

Browse files
committed
refactor: Provide centralized default impls for CommonSettings trait
1 parent 48ef413 commit 5de6ed4

File tree

4 files changed

+18
-39
lines changed

4 files changed

+18
-39
lines changed

crates/stackable-telemetry/src/tracing/settings/console_log.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Console Log Subscriber Settings.
22
3-
use tracing::level_filters::LevelFilter;
4-
53
use super::{Build, CommonSettings, Settings, SettingsBuilder};
64

75
/// Configure specific settings for the Console Log subscriber.
@@ -78,16 +76,8 @@ impl Build<ConsoleLogSettings> for SettingsBuilder {
7876
}
7977

8078
impl CommonSettings for ConsoleLogSettings {
81-
fn environment_variable(&self) -> &'static str {
82-
self.common_settings.environment_variable
83-
}
84-
85-
fn default_level(&self) -> LevelFilter {
86-
self.common_settings.default_level
87-
}
88-
89-
fn enabled(&self) -> bool {
90-
self.common_settings.enabled
79+
fn common(&self) -> &Settings {
80+
&self.common_settings
9181
}
9282
}
9383

crates/stackable-telemetry/src/tracing/settings/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,23 @@ pub use otlp_trace::*;
1313

1414
/// Simplifies access common settings from subscriber specific settings.
1515
pub trait CommonSettings {
16+
/// Access to common settings.
17+
fn common(&self) -> &Settings;
18+
1619
/// Access to the [`Settings::environment_variable`] field.
17-
fn environment_variable(&self) -> &'static str;
20+
fn environment_variable(&self) -> &'static str {
21+
self.common().environment_variable
22+
}
1823

1924
/// Access to the [`Settings::default_level`] field.
20-
fn default_level(&self) -> LevelFilter;
25+
fn default_level(&self) -> LevelFilter {
26+
self.common().default_level
27+
}
2128

2229
/// Access to the [`Settings::enabled`] field.
23-
fn enabled(&self) -> bool;
30+
fn enabled(&self) -> bool {
31+
self.common().enabled
32+
}
2433
}
2534

2635
/// General settings that apply to any subscriber.

crates/stackable-telemetry/src/tracing/settings/otlp_log.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! OTLP Log Subscriber Settings.
22
3-
use tracing::level_filters::LevelFilter;
4-
53
use super::{Build, CommonSettings, Settings, SettingsBuilder};
64

75
#[derive(Debug, Default, PartialEq)]
@@ -43,16 +41,8 @@ impl Build<OtlpLogSettings> for SettingsBuilder {
4341
}
4442

4543
impl CommonSettings for OtlpLogSettings {
46-
fn environment_variable(&self) -> &'static str {
47-
self.common_settings.environment_variable
48-
}
49-
50-
fn default_level(&self) -> LevelFilter {
51-
self.common_settings.default_level
52-
}
53-
54-
fn enabled(&self) -> bool {
55-
self.common_settings.enabled
44+
fn common(&self) -> &Settings {
45+
&self.common_settings
5646
}
5747
}
5848

crates/stackable-telemetry/src/tracing/settings/otlp_trace.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! OTLP Trace Subscriber Settings.
22
3-
use tracing::level_filters::LevelFilter;
4-
53
use super::{Build, CommonSettings, Settings, SettingsBuilder};
64

75
#[derive(Debug, Default, PartialEq)]
@@ -43,16 +41,8 @@ impl Build<OtlpTraceSettings> for SettingsBuilder {
4341
}
4442

4543
impl CommonSettings for OtlpTraceSettings {
46-
fn environment_variable(&self) -> &'static str {
47-
self.common_settings.environment_variable
48-
}
49-
50-
fn default_level(&self) -> LevelFilter {
51-
self.common_settings.default_level
52-
}
53-
54-
fn enabled(&self) -> bool {
55-
self.common_settings.enabled
44+
fn common(&self) -> &Settings {
45+
&self.common_settings
5646
}
5747
}
5848

0 commit comments

Comments
 (0)