MCPcopy Create free account
hub / github.com/dtormoen/tsk-tsk / stream_container_logs

Method stream_container_logs

src/docker/mod.rs:835–945  ·  view source on GitHub ↗

Stream container logs and process them through the log processor. Returns the accumulated log output and the container's exit code. `Err` is reserved for Docker API / infrastructure failures only.

(
        &self,
        container_id: &str,
        log_processor: &mut dyn LogProcessor,
        log_file: Option<std::fs::File>,
        suppress_stdout: bool,
    )

Source from the content-addressed store, hash-verified

833 /// Returns the accumulated log output and the container's exit code.
834 /// `Err` is reserved for Docker API / infrastructure failures only.
835 async fn stream_container_logs(
836 &self,
837 container_id: &str,
838 log_processor: &mut dyn LogProcessor,
839 log_file: Option<std::fs::File>,
840 suppress_stdout: bool,
841 ) -> Result<(String, i64), String> {
842 let mut log_file = log_file;
843 // Start a background task to stream logs
844 let client_clone = Arc::clone(&self.client);
845 let container_id_clone = container_id.to_string();
846 let (tx, mut rx) = tokio::sync::mpsc::channel::<String>(100);
847 let log_event_sender = self.event_sender.clone();
848
849 let log_task = tokio::spawn(async move {
850 let log_options = LogsOptions {
851 stdout: true,
852 stderr: true,
853 follow: true,
854 timestamps: false,
855 ..Default::default()
856 };
857
858 match client_clone
859 .logs_stream(&container_id_clone, Some(log_options))
860 .await
861 {
862 Ok(mut stream) => {
863 while let Some(result) = stream.next().await {
864 match result {
865 Ok(log_line) => {
866 if tx.send(log_line).await.is_err() {
867 break;
868 }
869 }
870 Err(e) => {
871 crate::tui::events::emit_or_print(
872 &log_event_sender,
873 crate::tui::events::ServerEvent::WarningMessage(format!(
874 "Error streaming logs: {e}"
875 )),
876 );
877 break;
878 }
879 }
880 }
881 }
882 Err(e) => {
883 crate::tui::events::emit_or_print(
884 &log_event_sender,
885 crate::tui::events::ServerEvent::WarningMessage(format!(
886 "Failed to start log streaming: {e}"
887 )),
888 );
889 }
890 }
891 });
892

Callers 1

run_container_innerMethod · 0.80

Calls 3

emit_or_printFunction · 0.85
logs_streamMethod · 0.45
wait_containerMethod · 0.45

Tested by

no test coverage detected