summaryrefslogtreecommitdiffstats
path: root/examples/logs.rs
blob: b35b0a3f2568abaee9d5fed471fe8dea805e162a (plain)
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
extern crate shiplift;
extern crate tokio;

use shiplift::{tty::StreamType, Docker, LogsOptions};
use std::env;
use tokio::prelude::{Future, Stream};

fn main() {
    let docker = Docker::new();
    let id = env::args()
        .nth(1)
        .expect("You need to specify a container id");
    let fut = docker
        .containers()
        .get(&id)
        .logs(&LogsOptions::builder().stdout(true).stderr(true).build())
        .for_each(|line| {
            match line.stream_type {
                StreamType::StdOut => println!("Stdout: {}", line.data),
                StreamType::StdErr => eprintln!("Stderr: {}", line.data),
            }
            Ok(())
        })
        .map_err(|e| eprintln!("Error: {}", e));

    tokio::run(fut);
}