1
0
Fork 0
mirror of https://codeberg.org/icewind/haze.git synced 2026-06-03 17:14:08 +02:00

service logs

This commit is contained in:
Robin Appelman 2021-03-19 18:42:40 +01:00
commit fe33330547
5 changed files with 61 additions and 27 deletions

View file

@ -1,3 +1,4 @@
use bollard::container::LogsOptions;
use bollard::exec::{CreateExecOptions, StartExecResults};
use bollard::Docker;
use color_eyre::{eyre::WrapErr, Result};
@ -119,3 +120,20 @@ pub async fn exec<S1: AsRef<str>, S2: Into<String>>(
.exit_code
.unwrap_or_default())
}
pub async fn container_logs(docker: &Docker, container: &str, count: usize) -> Result<Vec<String>> {
let mut logs = Vec::new();
let mut stream = docker.logs::<String>(
container,
Some(LogsOptions {
stdout: true,
stderr: true,
tail: format!("{}", count),
..Default::default()
}),
);
while let Some(line) = stream.next().await {
logs.push(line?.to_string());
}
Ok(logs)
}