mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 17:14:08 +02:00
service logs
This commit is contained in:
parent
fdee3d7cfa
commit
fe33330547
5 changed files with 61 additions and 27 deletions
18
src/exec.rs
18
src/exec.rs
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue