-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce log consumers (#681)
Introduce `LogConsumer` trait and ability to pass a consumer into `ContainerRequest`. The main advantage of this functionality is the use of background container output processing throughout the entire lifecycle of the container, starting from the moment of its creation. This way you can process logs even if the container was not started due to the wait strategy.
- Loading branch information
Showing
6 changed files
with
121 additions
and
7 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use futures::{future::BoxFuture, FutureExt}; | ||
|
||
use crate::core::logs::LogFrame; | ||
|
||
/// Log consumer is a trait that allows to consume log frames. | ||
/// Consumers will be called for each log frame that is produced by the container for the whole lifecycle of the container. | ||
pub trait LogConsumer: Send + Sync { | ||
fn accept<'a>(&'a self, record: &'a LogFrame) -> BoxFuture<'a, ()>; | ||
} | ||
|
||
impl<F> LogConsumer for F | ||
where | ||
F: Fn(&LogFrame) + Send + Sync, | ||
{ | ||
fn accept<'a>(&'a self, record: &'a LogFrame) -> BoxFuture<'a, ()> { | ||
// preferably to spawn blocking task | ||
async move { | ||
self(record); | ||
} | ||
.boxed() | ||
} | ||
} |
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