Skip to content

Commit

Permalink
Add Logging::for_container helper (#721)
Browse files Browse the repository at this point in the history
* Add Logging::for_container helper

* Changelog
  • Loading branch information
nightkr authored Jan 19, 2024
1 parent 6a794b9 commit 0375f8d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
- Add `iter()` methods to `KeyValuePairs<T>`, and delegate iter() for `Labels`, and `Annotations` ([#720]).
- Implement `IntoIterator` for `KeyValuePairs<T>`, `Labels` and `Annotations` ([#720]).
- Added `ListenerOperatorVolumeSourceBuilder::build_pvc` ([#719]).
- Added `Logging::for_container` ([#721]).

### Changed

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

## [0.61.0] - 2024-01-15

Expand Down
16 changes: 14 additions & 2 deletions src/product_logging/spec.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -81,6 +80,19 @@ where
pub containers: BTreeMap<T, ContainerLogConfig>,
}

impl<T> Logging<T>
where
T: Clone + Display + Ord,
{
/// Get the logging configuration for `container`, falling back to the default.
pub fn for_container(&self, container: &T) -> Cow<ContainerLogConfig> {
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"))]
Expand Down

0 comments on commit 0375f8d

Please sign in to comment.