From 6300a672b2e67c0cda6e0e9d4619b2ebf059b32e Mon Sep 17 00:00:00 2001 From: Kyle Kelley Date: Mon, 29 Jul 2024 14:23:35 -0700 Subject: [PATCH] repl: Log Jupyter kernel process stderr and stdout (#15391) Super simple piping of logs from the Jupyter kernels to the Zed logs. Release Notes: - Added logging of stderr from Jupyter kernels to the Zed logs --- crates/repl/src/kernels.rs | 4 ++-- crates/repl/src/session.rs | 31 ++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/crates/repl/src/kernels.rs b/crates/repl/src/kernels.rs index ad9ec27e74a5aab5ead6619305e1dd9d7545093d..2785bcf933a0a548a74ae45908d7f27318262a61 100644 --- a/crates/repl/src/kernels.rs +++ b/crates/repl/src/kernels.rs @@ -222,8 +222,8 @@ impl RunningKernel { let process = cmd .current_dir(&working_directory) - // .stdout(Stdio::null()) - // .stderr(Stdio::null()) + .stdout(std::process::Stdio::piped()) + .stderr(std::process::Stdio::piped()) .kill_on_drop(true) .spawn() .context("failed to start the kernel process")?; diff --git a/crates/repl/src/session.rs b/crates/repl/src/session.rs index 10330d78f63f5f59cb62641302f5fb3b1dbd530b..d5fa2cfc9d91917af8bb7751459e35fdaf2749d9 100644 --- a/crates/repl/src/session.rs +++ b/crates/repl/src/session.rs @@ -14,7 +14,8 @@ use editor::{ scroll::Autoscroll, Anchor, AnchorRangeExt as _, Editor, MultiBuffer, ToPoint, }; -use futures::{FutureExt as _, StreamExt as _}; +use futures::io::BufReader; +use futures::{AsyncBufReadExt as _, FutureExt as _, StreamExt as _}; use gpui::{ div, prelude::*, EntityId, EventEmitter, Model, Render, Subscription, Task, View, ViewContext, WeakView, @@ -242,6 +243,34 @@ impl Session { this.update(&mut cx, |session, cx| { // At this point we can create a new kind of kernel that has the process and our long running background tasks + let stderr = kernel.process.stderr.take(); + + cx.spawn(|_session, mut _cx| async move { + if let None = stderr { + return; + } + let reader = BufReader::new(stderr.unwrap()); + let mut lines = reader.lines(); + while let Some(Ok(line)) = lines.next().await { + log::error!("kernel: {}", line); + } + }) + .detach(); + + let stdout = kernel.process.stderr.take(); + + cx.spawn(|_session, mut _cx| async move { + if let None = stdout { + return; + } + let reader = BufReader::new(stdout.unwrap()); + let mut lines = reader.lines(); + while let Some(Ok(line)) = lines.next().await { + log::info!("kernel: {}", line); + } + }) + .detach(); + let status = kernel.process.status(); session.kernel(Kernel::RunningKernel(kernel), cx);