Skip to content
Snippets Groups Projects
Commit 79decd4a authored by Ian Jackson's avatar Ian Jackson
Browse files

logfiles: Introduce LogfileListConfigBuilder

In
  tpo/core/arti!462 (comment 2797697)
we decided not to do this.

However, having looked again at the way the FallbackList works, I
think there is a lot of value in making these two things (and anything
else like them[1]) as similar as possible.

[1] At least PreemptiveCircuitConfig.initial_predicted_ports and
NetworkConfig.authorities need the same treatment, and perhaps also
GuardUsage.restrictions (although there is no
GuardRestrictionBuilder).

In the irc discussion I imagined `LogfilesConfigBuilder` as opposed to
`LogfileConfigBuilder` (differing only in the `s`) which would be bad,
but we can use `List` instead.

We do *not* need to abstract away the validated version of the config.
Providing a type alias helps the derive_builder sub_builder DTRT
without needing special overrides.

I have split this commit so that we can drop it, if we conclude it's
not wanted.
parent 33565ea6
No related branches found
No related tags found
No related merge requests found
...@@ -39,14 +39,8 @@ pub struct LoggingConfig { ...@@ -39,14 +39,8 @@ pub struct LoggingConfig {
/// Configuration for one or more logfiles. /// Configuration for one or more logfiles.
#[serde(default)] #[serde(default)]
#[builder_field_attr(serde(default))] #[builder_field_attr(serde(default))]
#[builder( #[builder(sub_builder)]
setter(custom), files: LogfileListConfig,
field(
type = "Option<Vec<LogfileConfigBuilder>>",
build = "self.build_files()?"
)
)]
files: Vec<LogfileConfig>,
} }
/// Return a default tracing filter value for `logging.console`. /// Return a default tracing filter value for `logging.console`.
...@@ -68,20 +62,28 @@ impl LoggingConfig { ...@@ -68,20 +62,28 @@ impl LoggingConfig {
} }
} }
impl LoggingConfigBuilder { /// Local type alias, mostly helpful for derive_builder to DTRT
type LogfileListConfig = Vec<LogfileConfig>;
#[derive(Default, Clone, Deserialize)]
#[serde(transparent)]
/// List of logfiles to use, being built as part of the configuration
pub struct LogfileListConfigBuilder {
/// The logfiles, as overridden
files: Option<Vec<LogfileConfigBuilder>>,
}
impl LogfileListConfigBuilder {
/// Add a file logger /// Add a file logger
pub fn append_file(&mut self, file: LogfileConfigBuilder) -> &mut Self { pub fn append(&mut self, file: LogfileConfigBuilder) -> &mut Self {
self.files self.files
.get_or_insert_with(LoggingConfigBuilder::default_files) .get_or_insert_with(Self::default_files)
.push(file); .push(file);
self self
} }
/// Set the list of file loggers to the supplied `files` /// Set the list of file loggers to the supplied `files`
pub fn set_files( pub fn set(&mut self, files: impl IntoIterator<Item = LogfileConfigBuilder>) -> &mut Self {
&mut self,
files: impl IntoIterator<Item = LogfileConfigBuilder>,
) -> &mut Self {
self.files = Some(files.into_iter().collect()); self.files = Some(files.into_iter().collect());
self self
} }
...@@ -94,7 +96,7 @@ impl LoggingConfigBuilder { ...@@ -94,7 +96,7 @@ impl LoggingConfigBuilder {
} }
/// Resolve `LoggingConfigBuilder.files` to a value for `LoggingConfig.files` /// Resolve `LoggingConfigBuilder.files` to a value for `LoggingConfig.files`
pub(crate) fn build_files(&self) -> Result<Vec<LogfileConfig>, ConfigBuildError> { pub(crate) fn build(&self) -> Result<Vec<LogfileConfig>, ConfigBuildError> {
let default_buffer; let default_buffer;
let files = match &self.files { let files = match &self.files {
Some(files) => files, Some(files) => files,
......
...@@ -22,6 +22,12 @@ We can delete older sections here after we bump the releases. ...@@ -22,6 +22,12 @@ We can delete older sections here after we bump the releases.
BREAKING: Configuration of fallback directories overhauled; now uses FalllbadkDirBuilder more. BREAKING: Configuration of fallback directories overhauled; now uses FalllbadkDirBuilder more.
### arti
BREAKING: Replaced LoggingConfigBuilder::file (taking Vec) with LoggingConfigBuilder::files
BREAKING: LoggingConfigBuilder::build() throws ConfigBuildError, not a bespoke error
MODIFIED: LoggingConfigBuilder is now Deserialize
### tor-basic-util ### tor-basic-util
MODIFIED: Added `reset()` method to RetrySchedule. MODIFIED: Added `reset()` method to RetrySchedule.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment