mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-01-30 18:58:45 +08:00
Capture log from processes outside Livebook supervision (#1235)
Co-authored-by: Jonatan Kłosko <jonatanklosko@gmail.com>
This commit is contained in:
parent
fcf3015c87
commit
0c04f659c4
3 changed files with 22 additions and 4 deletions
|
@ -94,9 +94,12 @@ defmodule Livebook.Runtime.ErlDist.LoggerGLBackend do
|
|||
end
|
||||
|
||||
defp log_event(level, msg, ts, md, gl, state) do
|
||||
output = format_event(level, msg, ts, md, state)
|
||||
|
||||
if io_proxy?(gl) do
|
||||
output = format_event(level, msg, ts, md, state)
|
||||
async_io(gl, output)
|
||||
else
|
||||
send(Livebook.Runtime.ErlDist.NodeManager, {:orphan_log, output})
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -105,7 +108,7 @@ defmodule Livebook.Runtime.ErlDist.LoggerGLBackend do
|
|||
info[:dictionary][:"$initial_call"] == {Livebook.Runtime.Evaluator.IOProxy, :init, 1}
|
||||
end
|
||||
|
||||
defp async_io(device, output) when is_pid(device) do
|
||||
def async_io(device, output) when is_pid(device) do
|
||||
send(device, {:io_request, self(), make_ref(), {:put_chars, :unicode, output}})
|
||||
end
|
||||
|
||||
|
|
|
@ -151,6 +151,11 @@ defmodule Livebook.Runtime.ErlDist.NodeManager do
|
|||
end
|
||||
end
|
||||
|
||||
def handle_info({:orphan_log, _output} = message, state) do
|
||||
for pid <- state.runtime_servers, do: send(pid, message)
|
||||
{:noreply, state}
|
||||
end
|
||||
|
||||
def handle_info(_message, state), do: {:noreply, state}
|
||||
|
||||
@impl true
|
||||
|
|
|
@ -201,7 +201,8 @@ defmodule Livebook.Runtime.ErlDist.RuntimeServer do
|
|||
smart_cell_definitions_module:
|
||||
Keyword.get(opts, :smart_cell_definitions_module, Kino.SmartCell),
|
||||
extra_smart_cell_definitions: Keyword.get(opts, :extra_smart_cell_definitions, []),
|
||||
memory_timer_ref: nil
|
||||
memory_timer_ref: nil,
|
||||
last_evaluator: nil
|
||||
}}
|
||||
end
|
||||
|
||||
|
@ -244,6 +245,15 @@ defmodule Livebook.Runtime.ErlDist.RuntimeServer do
|
|||
{:noreply, finish_scan_binding(ref, state)}
|
||||
end
|
||||
|
||||
def handle_info({:orphan_log, output}, state) do
|
||||
with %{} = evaluator <- state.last_evaluator,
|
||||
{:group_leader, io_proxy} <- Process.info(evaluator.pid, :group_leader) do
|
||||
ErlDist.LoggerGLBackend.async_io(io_proxy, output)
|
||||
end
|
||||
|
||||
{:noreply, state}
|
||||
end
|
||||
|
||||
def handle_info(_message, state), do: {:noreply, state}
|
||||
|
||||
defp handle_down_evaluator(state, {:DOWN, _, :process, pid, reason}) do
|
||||
|
@ -338,7 +348,7 @@ defmodule Livebook.Runtime.ErlDist.RuntimeServer do
|
|||
opts
|
||||
)
|
||||
|
||||
{:noreply, state}
|
||||
{:noreply, %{state | last_evaluator: state.evaluators[container_ref]}}
|
||||
end
|
||||
|
||||
def handle_cast({:forget_evaluation, {container_ref, evaluation_ref}}, state) do
|
||||
|
|
Loading…
Reference in a new issue