Ignore io response messages when logging (#1997)

This commit is contained in:
Jonatan Kłosko 2023-06-21 00:40:21 +02:00 committed by GitHub
parent efb28fbdf0
commit d4e950bd05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 1 deletions

View file

@ -39,6 +39,7 @@ defmodule Livebook.Runtime.ErlDist do
Livebook.Runtime.ErlDist.IOForwardGL,
Livebook.Runtime.ErlDist.LoggerGLBackend,
Livebook.Runtime.ErlDist.LoggerGLHandler,
Livebook.Runtime.ErlDist.Sink,
Livebook.Runtime.ErlDist.SmartCellGL
]
end

View file

@ -13,7 +13,8 @@ defmodule Livebook.Runtime.ErlDist.LoggerGLHandler do
end
def async_io(device, output) when is_pid(device) do
send(device, {:io_request, self(), make_ref(), {:put_chars, :unicode, output}})
reply_to = Livebook.Runtime.ErlDist.Sink.pid()
send(device, {:io_request, reply_to, make_ref(), {:put_chars, :unicode, output}})
end
@doc false

View file

@ -98,6 +98,8 @@ defmodule Livebook.Runtime.ErlDist.NodeManager do
# TODO: remove logger backend once we require Elixir v1.15
if Code.ensure_loaded?(Logger) and function_exported?(Logger, :add_handlers, 1) do
{:ok, _pid} = Livebook.Runtime.ErlDist.Sink.start_link()
:logger.add_handler(:livebook_gl_handler, Livebook.Runtime.ErlDist.LoggerGLHandler, %{
formatter: Logger.Formatter.new(),
filters: [

View file

@ -0,0 +1,35 @@
defmodule Livebook.Runtime.ErlDist.Sink do
@moduledoc false
# An idle process that ignores all incoming messages.
use GenServer
@name __MODULE__
@doc """
Starts the process.
"""
@spec start_link() :: GenServer.on_start()
def start_link() do
GenServer.start_link(__MODULE__, {}, name: @name)
end
@doc """
Returns pid of the global sink process.
"""
@spec pid() :: pid()
def pid() do
Process.whereis(@name)
end
@impl true
def init({}) do
{:ok, {}}
end
@impl true
def handle_info(_message, state) do
{:noreply, state}
end
end