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
2 changes: 1 addition & 1 deletion lib/logger/lib/logger/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Logger.Utils do
@doc """
A filter for default translation and handling of reports.
"""
def translator(%{domain: [:elixir | _]}, %{otp: false}), do: :stop
def translator(%{meta: %{domain: [:otp | _]}}, %{otp: false}), do: :stop
def translator(%{meta: %{domain: [:otp, :sasl | _]}}, %{sasl: false}), do: :stop
def translator(%{meta: %{domain: [:supervisor_report | _]}}, %{sasl: false}), do: :stop
def translator(%{msg: {:string, _}}, _config), do: :ignore
Expand Down
60 changes: 46 additions & 14 deletions lib/logger/test/logger/translator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,27 @@ defmodule Logger.TranslatorTest do
end

setup_all do
sasl_reports? = Application.get_env(:logger, :handle_sasl_reports, false)
Application.put_env(:logger, :handle_sasl_reports, true)
config = Application.get_all_env(:logger)

# Shutdown the application
Logger.App.stop()
config
|> Keyword.put(:handle_sasl_reports, true)
|> put_logger_config()

# And start it without warnings
Application.put_env(:logger, :level, :error)
Application.start(:logger)
Application.delete_env(:logger, :level)
Logger.configure(level: :debug)
on_exit(fn -> restore_logger_config(config) end)
end

on_exit(fn ->
Application.put_env(:logger, :handle_sasl_reports, sasl_reports?)
Logger.App.stop()
Application.start(:logger)
end)
setup context do
test_overrides = Map.get(context, :logger_config, [])
existing_config = Application.get_all_env(:logger)

case Keyword.merge(existing_config, test_overrides) do
^existing_config ->
:ok

new_config ->
put_logger_config(new_config)
on_exit(fn -> restore_logger_config(existing_config) end)
end
end

setup do
Expand Down Expand Up @@ -1259,6 +1263,13 @@ defmodule Logger.TranslatorTest do
:code.delete(WeirdFunctionNamesGenServer)
end

@tag logger_config: [handle_otp_reports: false]
test "drops events if otp report handling is switched off" do
{:ok, pid} = GenServer.start(MyGenServer, :ok)
catch_exit(GenServer.call(pid, :error))
refute_receive {:event, _, _}, 200
end

def task(parent, fun \\ fn -> raise "oops" end) do
mon = Process.monitor(parent)
Process.unlink(parent)
Expand Down Expand Up @@ -1312,4 +1323,25 @@ defmodule Logger.TranslatorTest do
defp worker(name, args, opts \\ []) do
Enum.into(opts, %{id: name, start: {name, opts[:function] || :start_link, args}})
end

defp put_logger_config(new_config) do
Application.put_all_env(logger: new_config)

Logger.App.stop()

# Shutdown the application
Logger.App.stop()

# And start it without warnings
Application.put_env(:logger, :level, :error)
Application.start(:logger)
Application.delete_env(:logger, :level)
Logger.configure(level: :debug)
end

defp restore_logger_config(config) do
Application.put_all_env(logger: config)
Logger.App.stop()
Application.start(:logger)
end
end
Loading