forked from kube-rs/kube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_stream.rs
35 lines (31 loc) · 863 Bytes
/
log_stream.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use anyhow::{anyhow, Result};
use futures::{StreamExt, TryStreamExt};
use k8s_openapi::api::core::v1::Pod;
use kube::{
api::{Api, LogParams},
Client,
};
use std::env;
use tracing::*;
#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::fmt::init();
let client = Client::try_default().await?;
let mypod = env::args()
.nth(1)
.ok_or_else(|| anyhow!("Usage: log_follow <pod>"))?;
info!("Fetching logs for {:?}", mypod);
let pods: Api<Pod> = Api::default_namespaced(client);
let mut logs = pods
.log_stream(&mypod, &LogParams {
follow: true,
tail_lines: Some(1),
..LogParams::default()
})
.await?
.boxed();
while let Some(line) = logs.try_next().await? {
info!("{:?}", String::from_utf8_lossy(&line));
}
Ok(())
}