diff --git a/lib/bandit.ex b/lib/bandit.ex index 057009c2..33e416f8 100644 --- a/lib/bandit.ex +++ b/lib/bandit.ex @@ -313,11 +313,14 @@ defmodule Bandit do |> ThousandIsland.start_link() |> case do {:ok, pid} -> - startup_log && Logger.log(startup_log, info(scheme, display_plug, pid)) + startup_log && Logger.log(startup_log, info(scheme, display_plug, pid), domain: [:bandit]) {:ok, pid} {:error, {:shutdown, {:failed_to_start_child, :listener, :eaddrinuse}}} = error -> - Logger.error([info(scheme, display_plug, nil), " failed, port #{port} already in use"]) + Logger.error([info(scheme, display_plug, nil), " failed, port #{port} already in use"], + domain: [:bandit] + ) + error {:error, _} = error -> diff --git a/lib/bandit/clock.ex b/lib/bandit/clock.ex index bd87c611..64dcb4b4 100644 --- a/lib/bandit/clock.ex +++ b/lib/bandit/clock.ex @@ -22,7 +22,7 @@ defmodule Bandit.Clock do :ets.lookup_element(__MODULE__, :date_header, 2) rescue ArgumentError -> - Logger.warning("Header timestamp couldn't be fetched from ETS cache") + Logger.warning("Header timestamp couldn't be fetched from ETS cache", domain: [:bandit]) get_date_header() end diff --git a/lib/bandit/http2/connection.ex b/lib/bandit/http2/connection.ex index 9647b2c6..4edab3dc 100644 --- a/lib/bandit/http2/connection.ex +++ b/lib/bandit/http2/connection.ex @@ -203,7 +203,7 @@ defmodule Bandit.HTTP2.Connection do # Catch-all handler for unknown frame types def handle_frame(%Bandit.HTTP2.Frame.Unknown{} = frame, _socket, connection) do - Logger.warning("Unknown frame (#{inspect(Map.from_struct(frame))})") + Logger.warning("Unknown frame (#{inspect(Map.from_struct(frame))})", domain: [:bandit]) connection end diff --git a/lib/bandit/http2/handler.ex b/lib/bandit/http2/handler.ex index 9c1ca86c..5a334fae 100644 --- a/lib/bandit/http2/handler.ex +++ b/lib/bandit/http2/handler.ex @@ -19,9 +19,16 @@ defmodule Bandit.HTTP2.Handler do rescue error -> case Keyword.get(state.opts.http, :log_protocol_errors, :short) do - :short -> Logger.error(Exception.format_banner(:error, error, __STACKTRACE__)) - :verbose -> Logger.error(Exception.format(:error, error, __STACKTRACE__)) - false -> :ok + :short -> + Logger.error(Exception.format_banner(:error, error, __STACKTRACE__), + domain: [:bandit] + ) + + :verbose -> + Logger.error(Exception.format(:error, error, __STACKTRACE__), domain: [:bandit]) + + false -> + :ok end {:close, state} diff --git a/lib/bandit/http2/stream.ex b/lib/bandit/http2/stream.ex index c7194bc9..b0fed306 100644 --- a/lib/bandit/http2/stream.ex +++ b/lib/bandit/http2/stream.ex @@ -243,7 +243,7 @@ defmodule Bandit.HTTP2.Stream do case do_recv(stream, timeout) do {:headers, trailers, stream} -> no_pseudo_headers!(trailers) - Logger.warning("Ignoring trailers #{inspect(trailers)}") + Logger.warning("Ignoring trailers #{inspect(trailers)}", domain: [:bandit]) do_read_data(stream, max_bytes, timeout, acc) {:data, data, stream} -> diff --git a/lib/bandit/initial_handler.ex b/lib/bandit/initial_handler.ex index b62b99c6..27a0a0d4 100644 --- a/lib/bandit/initial_handler.ex +++ b/lib/bandit/initial_handler.ex @@ -22,7 +22,10 @@ defmodule Bandit.InitialHandler do def handle_connection(socket, state) do case {state.http_1_enabled, state.http_2_enabled, alpn_protocol(socket), sniff_wire(socket)} do {_, _, _, :likely_tls} -> - Logger.warning("Connection that looks like TLS received on a clear channel") + Logger.warning("Connection that looks like TLS received on a clear channel", + domain: [:bandit] + ) + {:close, state} {_, true, Bandit.HTTP2.Handler, Bandit.HTTP2.Handler} -> diff --git a/lib/bandit/logger.ex b/lib/bandit/logger.ex index 52d09a86..46ce4edd 100644 --- a/lib/bandit/logger.ex +++ b/lib/bandit/logger.ex @@ -69,7 +69,8 @@ defmodule Bandit.Logger do ) :: :ok def log_error(event, measurements, metadata, _config) do Logger.error( - "#{inspect(event)} metadata: #{inspect(metadata)}, measurements: #{inspect(measurements)}" + "#{inspect(event)} metadata: #{inspect(metadata)}, measurements: #{inspect(measurements)}", + domain: [:bandit] ) end @@ -82,7 +83,8 @@ defmodule Bandit.Logger do ) :: :ok def log_info(event, measurements, metadata, _config) do Logger.info( - "#{inspect(event)} metadata: #{inspect(metadata)}, measurements: #{inspect(measurements)}" + "#{inspect(event)} metadata: #{inspect(metadata)}, measurements: #{inspect(measurements)}", + domain: [:bandit] ) end end diff --git a/lib/bandit/pipeline.ex b/lib/bandit/pipeline.ex index 392ea185..8d40341a 100644 --- a/lib/bandit/pipeline.ex +++ b/lib/bandit/pipeline.ex @@ -209,9 +209,14 @@ defmodule Bandit.Pipeline do Bandit.Telemetry.stop_span(span, %{}, %{error: error.message}) case Keyword.get(opts.http, :log_protocol_errors, :short) do - :short -> Logger.error(Exception.format_banner(:error, error, stacktrace)) - :verbose -> Logger.error(Exception.format(:error, error, stacktrace)) - false -> :ok + :short -> + Logger.error(Exception.format_banner(:error, error, stacktrace), domain: [:bandit]) + + :verbose -> + Logger.error(Exception.format(:error, error, stacktrace), domain: [:bandit]) + + false -> + :ok end # We want to do this at the end of the function, since the HTTP2 stack may kill this process @@ -225,7 +230,7 @@ defmodule Bandit.Pipeline do status = error |> Plug.Exception.status() |> Plug.Conn.Status.code() if status in Keyword.get(opts.http, :log_exceptions_with_status_codes, 500..599) do - Logger.error(Exception.format(:error, error, stacktrace)) + Logger.error(Exception.format(:error, error, stacktrace), domain: [:bandit]) Bandit.HTTPTransport.send_on_error(transport, error) {:error, error} else