Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/logger/lib/logger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ defmodule Logger do

* `:registered_name` - the process registered name as an atom

* `:process_label` - (available from Erlang/OTP 27+) an arbitrary term
which can be added to a process with `:proc_lib.set_label/1` for
debugging purposes

* `:domain` - a list of domains for the logged message. For example,
all Elixir reports default to `[:elixir]`. Erlang reports may start
with `[:otp]` or `[:sasl]`
Expand Down
6 changes: 5 additions & 1 deletion lib/logger/lib/logger/translator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,14 @@ defmodule Logger.Translator do
[prefix, "Ancestors: ", inspect(ancestors) | crash_info(min_level, debug, prefix)]
end

defp crash_info(min_level, [{:process_label, _} | info], prefix) do
defp crash_info(min_level, [{:process_label, :undefined} | info], prefix) do
crash_info(min_level, info, prefix)
end

defp crash_info(min_level, [{:process_label, label} | debug], prefix) do
[prefix, "Process Label: ", inspect(label) | crash_info(min_level, debug, prefix)]
end

defp crash_info(:debug, debug, prefix) do
for {key, value} <- debug do
crash_debug(key, value, prefix)
Expand Down
27 changes: 27 additions & 0 deletions lib/logger/test/logger/translator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,33 @@ defmodule Logger.TranslatorTest do
assert {%RuntimeError{message: "oops"}, [_ | _]} = process_metadata[:crash_reason]
end

@tag skip: System.otp_release() < "27"
test "translates :proc_lib crashes with :process_label" do
fun = fn ->
:proc_lib.set_label({:any, "term"})
raise "oops"
end

pid = :proc_lib.spawn_link(__MODULE__, :task, [self(), fun])

assert capture_log(:info, fn ->
ref = Process.monitor(pid)
send(pid, :message)
send(pid, :go)
receive do: ({:DOWN, ^ref, _, _, _} -> :ok)
end) =~ ~r"""
\[error\] Process #PID<\d+\.\d+\.\d+> terminating
\*\* \(RuntimeError\) oops
.*
Initial Call: Logger.TranslatorTest.task/2
Process Label: {:any, \"term\"}
Ancestors: \[#PID<\d+\.\d+\.\d+>\]
"""s

assert_receive {:event, {:string, ["Process " | _]}, process_metadata}
assert {%RuntimeError{message: "oops"}, [_ | _]} = process_metadata[:crash_reason]
end

test "translates :proc_lib crashes without initial call" do
fun = fn ->
Process.delete(:"$initial_call")
Expand Down