diff --git a/CHANGELOG.md b/CHANGELOG.md index f0041d859..dbed92751 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. - Added `Option::as_ref_or_else` to `utils` ([#717]). - Added `ListenerOperatorVolumeSourceBuilder::build_pvc` ([#719]). +- Added `Logging::for_container` ([#721]). ### Changed @@ -16,6 +17,7 @@ All notable changes to this project will be documented in this file. [#717]: https://github.com/stackabletech/operator-rs/pull/717 [#719]: https://github.com/stackabletech/operator-rs/pull/719 +[#721]: https://github.com/stackabletech/operator-rs/pull/721 ## [0.61.0] - 2024-01-15 diff --git a/src/product_logging/spec.rs b/src/product_logging/spec.rs index 071e31d9a..5e9c1df83 100644 --- a/src/product_logging/spec.rs +++ b/src/product_logging/spec.rs @@ -1,7 +1,6 @@ //! Logging structure used within Custom Resource Definitions -use std::collections::BTreeMap; -use std::fmt::Display; +use std::{borrow::Cow, collections::BTreeMap, fmt::Display}; use crate::config::{ fragment::{self, Fragment, FromFragment}, @@ -81,6 +80,19 @@ where pub containers: BTreeMap, } +impl Logging +where + T: Clone + Display + Ord, +{ + /// Get the logging configuration for `container`, falling back to the default. + pub fn for_container(&self, container: &T) -> Cow { + self.containers + .get(container) + .map(Cow::Borrowed) + .unwrap_or_default() + } +} + /// Log configuration of the container #[derive(Clone, Debug, Default, Eq, Fragment, JsonSchema, PartialEq)] #[fragment(path_overrides(fragment = "crate::config::fragment"))]