-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(stackable-telemetry): Add RollingFileAppender (#933)
* feat: add RollingFileAppender to stackable-telemetry * add changelog entry * adjust docs * adjust docs * error handling, simplify filelogsettings creation * Apply suggestions from code review Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com> * fix use statement * Update crates/stackable-telemetry/src/tracing/mod.rs Co-authored-by: Techassi <git@techassi.dev> --------- Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com> Co-authored-by: Techassi <git@techassi.dev>
- Loading branch information
1 parent
fc222e4
commit 4c2bfaa
Showing
6 changed files
with
164 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
crates/stackable-telemetry/src/tracing/settings/file_log.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//! File Log Subscriber Settings. | ||
use std::{ops::Deref, path::PathBuf}; | ||
|
||
use super::Settings; | ||
|
||
/// Configure specific settings for the File Log subscriber. | ||
#[derive(Debug, Default, PartialEq)] | ||
pub struct FileLogSettings { | ||
/// Common subscriber settings that apply to the File Log Subscriber. | ||
pub common_settings: Settings, | ||
|
||
/// Path to directory for log files. | ||
pub file_log_dir: PathBuf, | ||
} | ||
|
||
impl Deref for FileLogSettings { | ||
type Target = Settings; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.common_settings | ||
} | ||
} | ||
|
||
/// For building [`FileLogSettings`]. | ||
/// | ||
/// <div class="warning"> | ||
/// Do not use directly, instead use the [`Settings::builder`] associated function. | ||
/// </div> | ||
pub struct FileLogSettingsBuilder { | ||
pub(crate) common_settings: Settings, | ||
pub(crate) file_log_dir: PathBuf, | ||
} | ||
|
||
impl FileLogSettingsBuilder { | ||
/// Consumes self and returns a valid [`FileLogSettings`] instance. | ||
pub fn build(self) -> FileLogSettings { | ||
FileLogSettings { | ||
common_settings: self.common_settings, | ||
file_log_dir: self.file_log_dir, | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use tracing::level_filters::LevelFilter; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn builds_settings() { | ||
let expected = FileLogSettings { | ||
common_settings: Settings { | ||
environment_variable: "hello", | ||
default_level: LevelFilter::DEBUG, | ||
enabled: true, | ||
}, | ||
file_log_dir: PathBuf::from("/logs"), | ||
}; | ||
let result = Settings::builder() | ||
.with_environment_variable("hello") | ||
.with_default_level(LevelFilter::DEBUG) | ||
.enabled(true) | ||
.file_log_settings_builder(PathBuf::from("/logs")) | ||
.build(); | ||
|
||
assert_eq!(expected, result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters