1+ //! Subscriber settings.
2+
13use tracing:: level_filters:: LevelFilter ;
24
35pub mod console_log;
@@ -9,23 +11,40 @@ pub use otlp_log::*;
911pub mod otlp_trace;
1012pub use otlp_trace:: * ;
1113
12- // this trait is to make it simpler to access common settings from specific settings.
14+ /// Simplifies access common settings from subscriber specific settings.
1315pub trait CommonSettings {
16+ /// Access to the [`Settings::environment_variable`] field.
1417 fn environment_variable ( & self ) -> & ' static str ;
18+
19+ /// Access to the [`Settings::default_level`] field.
1520 fn default_level ( & self ) -> LevelFilter ;
21+
22+ /// Access to the [`Settings::enabled`] field.
1623 fn enabled ( & self ) -> bool ;
1724}
1825
26+ /// General settings that apply to any subscriber.
1927#[ derive( Debug , PartialEq ) ]
2028pub struct Settings {
29+ /// The environment variable used to set the [`LevelFilter`].
30+ ///
31+ /// When the environment variable is set, it will override what is set by
32+ /// [`Self::default_level`].
2133 pub environment_variable : & ' static str ,
2234
35+ /// The [`LevelFilter`] to fallback to if [`Self::environment_variable`] has
36+ /// not been set.
2337 pub default_level : LevelFilter ,
2438
39+ /// Whether or not the subscriber is enabled.
40+ ///
41+ /// When set to `true`, the [`tracing::Subscriber`] will be added to the
42+ /// [`tracing_subscriber::Layer`] list.
2543 pub enabled : bool ,
2644}
2745
2846impl Settings {
47+ /// Builder methods to override defaults.
2948 pub fn builder ( ) -> SettingsBuilder {
3049 SettingsBuilder :: default ( )
3150 }
@@ -37,13 +56,16 @@ impl Default for Settings {
3756 }
3857}
3958
59+ /// For building [`Settings`].
4060pub struct SettingsBuilder {
4161 environment_variable : & ' static str ,
4262 enabled : bool ,
4363 default_level : LevelFilter ,
4464}
4565
66+ /// Finalizer to be implemented on builders.
4667pub trait Build < T > {
68+ /// Finalize settings.
4769 fn build ( self ) -> T ;
4870}
4971
@@ -54,16 +76,27 @@ impl Build<Settings> for SettingsBuilder {
5476}
5577
5678impl SettingsBuilder {
79+ /// Set the environment variable used for overriding the [`Settings::default_level`].
80+ ///
81+ /// Defaults to `RUST_LOG`.
82+ // TODO (@NickLarsenNZ): set a constant for the default environment variable.
5783 pub fn with_environment_variable ( mut self , name : & ' static str ) -> Self {
5884 self . environment_variable = name;
5985 self
6086 }
6187
88+ /// Set the default [`LevelFilter`].
89+ ///
90+ /// Defaults to [`LevelFilter::OFF`].
91+ // TODO (@NickLarsenNZ): set a constant for the default level.
6292 pub fn with_default_level ( mut self , level : impl Into < LevelFilter > ) -> Self {
6393 self . default_level = level. into ( ) ;
6494 self
6595 }
6696
97+ /// Enable or disable the [`tracing::Subscriber`].
98+ ///
99+ /// Defaults to `false`.
67100 // TODO (@NickLarsenNZ): Currently this has to be called to enable the
68101 // subscriber. Eventually it should become optional, and default to on (if
69102 // settings are supplied). Therefore, the fields in TracingBuilder to hold
@@ -75,14 +108,17 @@ impl SettingsBuilder {
75108 self
76109 }
77110
111+ /// Set specific [`ConsoleLogSettings`].
78112 pub fn console_log_settings_builder ( self ) -> ConsoleLogSettingsBuilder {
79113 self . into ( )
80114 }
81115
116+ /// Set specific [`OtlpLogSettings`].
82117 pub fn otlp_log_settings_builder ( self ) -> OtlpLogSettingsBuilder {
83118 self . into ( )
84119 }
85120
121+ /// Set specific [`OtlpTraceSettings`].
86122 pub fn otlp_trace_settings_builder ( self ) -> OtlpTraceSettingsBuilder {
87123 self . into ( )
88124 }
0 commit comments