Skip to content

Commit b545a1e

Browse files
committed
Translate emulator logged process crashes in 18.0+
Signed-off-by: James Fish <[email protected]>
1 parent c08b5b1 commit b545a1e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/logger/lib/logger/translator.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ defmodule Logger.Translator do
5353
"** (exit) " <> Exception.format_exit(reason)
5454
{:ok, msg}
5555

56+
{'Error in process ' ++ _, [pid, {reason, stack}]} ->
57+
msg = ["Process ", inspect(pid), " raised an exception" |
58+
format(:error, reason, stack)]
59+
{:ok, msg}
60+
5661
_ ->
5762
:none
5863
end

lib/logger/test/logger/translator_test.exs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,21 @@ defmodule Logger.TranslatorTest do
154154
"""
155155
end
156156

157+
test "translates Process crashes" do
158+
if :erlang.system_info(:otp_release) >= '18' do
159+
assert capture_log(:info, fn ->
160+
{_, ref} = spawn_monitor(fn() -> raise "oops" end)
161+
receive do: ({:DOWN, ^ref, _, _, _} -> :ok)
162+
# Even though the monitor has been received the emulator may not have
163+
# sent the message to the error logger
164+
:timer.sleep(200)
165+
end) =~ ~r"""
166+
\[error\] Process #PID<\d+\.\d+\.\d+>\ raised an exception
167+
\*\* \(RuntimeError\) oops
168+
"""
169+
end
170+
end
171+
157172
test "translates :proc_lib crashes with name" do
158173
{:ok, pid} = Task.start_link(__MODULE__, :task,
159174
[self(), fn() ->

0 commit comments

Comments
 (0)