Skip to content

Commit 0375f8d

Browse files
authored
Add Logging::for_container helper (#721)
* Add Logging::for_container helper * Changelog
1 parent 6a794b9 commit 0375f8d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
1010
- Add `iter()` methods to `KeyValuePairs<T>`, and delegate iter() for `Labels`, and `Annotations` ([#720]).
1111
- Implement `IntoIterator` for `KeyValuePairs<T>`, `Labels` and `Annotations` ([#720]).
1212
- Added `ListenerOperatorVolumeSourceBuilder::build_pvc` ([#719]).
13+
- Added `Logging::for_container` ([#721]).
1314

1415
### Changed
1516

@@ -20,6 +21,7 @@ All notable changes to this project will be documented in this file.
2021
[#717]: https://github.com/stackabletech/operator-rs/pull/717
2122
[#720]: https://github.com/stackabletech/operator-rs/pull/720
2223
[#719]: https://github.com/stackabletech/operator-rs/pull/719
24+
[#721]: https://github.com/stackabletech/operator-rs/pull/721
2325

2426
## [0.61.0] - 2024-01-15
2527

src/product_logging/spec.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Logging structure used within Custom Resource Definitions
22
3-
use std::collections::BTreeMap;
4-
use std::fmt::Display;
3+
use std::{borrow::Cow, collections::BTreeMap, fmt::Display};
54

65
use crate::config::{
76
fragment::{self, Fragment, FromFragment},
@@ -81,6 +80,19 @@ where
8180
pub containers: BTreeMap<T, ContainerLogConfig>,
8281
}
8382

83+
impl<T> Logging<T>
84+
where
85+
T: Clone + Display + Ord,
86+
{
87+
/// Get the logging configuration for `container`, falling back to the default.
88+
pub fn for_container(&self, container: &T) -> Cow<ContainerLogConfig> {
89+
self.containers
90+
.get(container)
91+
.map(Cow::Borrowed)
92+
.unwrap_or_default()
93+
}
94+
}
95+
8496
/// Log configuration of the container
8597
#[derive(Clone, Debug, Default, Eq, Fragment, JsonSchema, PartialEq)]
8698
#[fragment(path_overrides(fragment = "crate::config::fragment"))]

0 commit comments

Comments
 (0)