summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/rabbitmq.config.example4
-rw-r--r--src/rabbit_log.erl11
-rw-r--r--src/rabbit_reader.erl46
3 files changed, 48 insertions, 13 deletions
diff --git a/docs/rabbitmq.config.example b/docs/rabbitmq.config.example
index 63540568..fdb166ea 100644
--- a/docs/rabbitmq.config.example
+++ b/docs/rabbitmq.config.example
@@ -33,8 +33,8 @@
%% {handshake_timeout, 10000},
%% Log levels (currently just used for connection logging).
- %% One of 'info', 'warning', 'error' or 'none', in decreasing order
- %% of verbosity. Defaults to 'info'.
+ %% One of 'debug', 'info', 'warning', 'error' or 'none', in decreasing
+ %% order of verbosity. Defaults to 'info'.
%%
%% {log_levels, [{connection, info}]},
diff --git a/src/rabbit_log.erl b/src/rabbit_log.erl
index e05ef05a..6f0865b3 100644
--- a/src/rabbit_log.erl
+++ b/src/rabbit_log.erl
@@ -16,7 +16,8 @@
-module(rabbit_log).
--export([log/3, log/4, info/1, info/2, warning/1, warning/2, error/1, error/2]).
+-export([log/3, log/4, debug/1, debug/2, info/1, info/2, warning/1,
+ warning/2, error/1, error/2]).
-export([with_local_io/1]).
%%----------------------------------------------------------------------------
@@ -26,11 +27,13 @@
-export_type([level/0]).
-type(category() :: atom()).
--type(level() :: 'info' | 'warning' | 'error').
+-type(level() :: 'debug' | 'info' | 'warning' | 'error').
-spec(log/3 :: (category(), level(), string()) -> 'ok').
-spec(log/4 :: (category(), level(), string(), [any()]) -> 'ok').
+-spec(debug/1 :: (string()) -> 'ok').
+-spec(debug/2 :: (string(), [any()]) -> 'ok').
-spec(info/1 :: (string()) -> 'ok').
-spec(info/2 :: (string(), [any()]) -> 'ok').
-spec(warning/1 :: (string()) -> 'ok').
@@ -50,6 +53,7 @@ log(Category, Level, Fmt, Args) when is_list(Args) ->
case level(Level) =< catlevel(Category) of
false -> ok;
true -> F = case Level of
+ debug -> fun error_logger:info_msg/2;
info -> fun error_logger:info_msg/2;
warning -> fun error_logger:warning_msg/2;
error -> fun error_logger:error_msg/2
@@ -57,6 +61,8 @@ log(Category, Level, Fmt, Args) when is_list(Args) ->
with_local_io(fun () -> F(Fmt, Args) end)
end.
+debug(Fmt) -> log(default, debug, Fmt).
+debug(Fmt, Args) -> log(default, debug, Fmt, Args).
info(Fmt) -> log(default, info, Fmt).
info(Fmt, Args) -> log(default, info, Fmt, Args).
warning(Fmt) -> log(default, warning, Fmt).
@@ -75,6 +81,7 @@ catlevel(Category) ->
%%--------------------------------------------------------------------
+level(debug) -> 4;
level(info) -> 3;
level(warning) -> 2;
level(error) -> 1;
diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl
index c92eaf7f..8c545467 100644
--- a/src/rabbit_reader.erl
+++ b/src/rabbit_reader.erl
@@ -219,7 +219,6 @@ start_connection(Parent, HelperSup, Deb, Sock, SockTransform) ->
rabbit_net:fast_close(Sock),
exit(normal)
end,
- log(info, "accepting AMQP connection ~p (~s)~n", [self(), Name]),
{ok, HandshakeTimeout} = application:get_env(rabbit, handshake_timeout),
ClientSock = socket_op(Sock, SockTransform),
erlang:send_after(HandshakeTimeout, self(), handshake_timeout),
@@ -265,8 +264,9 @@ start_connection(Parent, HelperSup, Deb, Sock, SockTransform) ->
log(info, "closing AMQP connection ~p (~s)~n", [self(), Name])
catch
Ex -> log(case Ex of
- connection_closed_abruptly -> warning;
- _ -> error
+ connection_closed_with_no_data_received -> debug;
+ connection_closed_abruptly -> warning;
+ _ -> error
end, "closing AMQP connection ~p (~s):~n~p~n",
[self(), Name, Ex])
after
@@ -318,8 +318,28 @@ binlist_split(Len, L, [Acc0|Acc]) when Len < 0 ->
binlist_split(Len, [H|T], Acc) ->
binlist_split(Len - size(H), T, [H|Acc]).
-mainloop(Deb, Buf, BufLen, State = #v1{sock = Sock}) ->
- case rabbit_net:recv(Sock) of
+mainloop(Deb, Buf, BufLen, State = #v1{sock = Sock,
+ connection_state = CS,
+ connection = #connection{
+ name = ConnName}}) ->
+ Recv = rabbit_net:recv(Sock),
+ case CS of
+ pre_init when Buf =:= [] ->
+ %% We only new incoming connections only when either the
+ %% first byte was received or there was an error (eg. a
+ %% timeout).
+ %%
+ %% The goal is to not log TCP healthchecks (a connection
+ %% with no data received) unless specified otherwise.
+ log(case Recv of
+ closed -> debug;
+ _ -> info
+ end, "accepting AMQP connection ~p (~s)~n",
+ [self(), ConnName]);
+ _ ->
+ ok
+ end,
+ case Recv of
{data, Data} ->
recvloop(Deb, [Data | Buf], BufLen + size(Data),
State#v1{pending_recv = false});
@@ -339,10 +359,18 @@ mainloop(Deb, Buf, BufLen, State = #v1{sock = Sock}) ->
end
end.
-stop(closed, State) -> maybe_emit_stats(State),
- throw(connection_closed_abruptly);
-stop(Reason, State) -> maybe_emit_stats(State),
- throw({inet_error, Reason}).
+stop(closed, #v1{connection_state = pre_init} = State) ->
+ %% The connection was closed before any packet was received. It's
+ %% probably a load-balancer healthcheck: don't consider this a
+ %% failure.
+ maybe_emit_stats(State),
+ throw(connection_closed_with_no_data_received);
+stop(closed, State) ->
+ maybe_emit_stats(State),
+ throw(connection_closed_abruptly);
+stop(Reason, State) ->
+ maybe_emit_stats(State),
+ throw({inet_error, Reason}).
handle_other({conserve_resources, Source, Conserve},
State = #v1{throttle = Throttle = #throttle{alarmed_by = CR}}) ->