summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniil Fedotov <dfedotov@pivotal.io>2017-08-07 14:52:39 +0100
committerDaniil Fedotov <dfedotov@pivotal.io>2017-08-07 14:52:39 +0100
commite24220800789e07f6c9d7eb6988210d342d59352 (patch)
tree588496ce5cf3233d2a003ae23478ee7aa6788e21 /src
parent1c63b80ae46aebec3f90803439aeb79a41ffe56b (diff)
downloadrabbitmq-server-git-e24220800789e07f6c9d7eb6988210d342d59352.tar.gz
Use lager sink API for logs.
Lager sink parse-transform allows us to use a fake module name to select sinks. It's more convenient that to use a helper function for every module. Get rif of `rabbit_log_connection` as a sink qualifier. Qualifiers should be compatible with pre-3.7 qualifiers for plugin developers. [#149634975]
Diffstat (limited to 'src')
-rw-r--r--src/rabbit_mirror_queue_misc.erl12
-rw-r--r--src/rabbit_reader.erl59
2 files changed, 41 insertions, 30 deletions
diff --git a/src/rabbit_mirror_queue_misc.erl b/src/rabbit_mirror_queue_misc.erl
index 725cd7d089..a6571defcb 100644
--- a/src/rabbit_mirror_queue_misc.erl
+++ b/src/rabbit_mirror_queue_misc.erl
@@ -262,12 +262,12 @@ report_deaths(MirrorPid, IsMaster, QueueName, DeadPids) ->
rabbit_misc:pid_to_string(MirrorPid),
[[$ , rabbit_misc:pid_to_string(P)] || P <- DeadPids]]).
-log_info (QName, Fmt, Args) -> log(info, QName, Fmt, Args).
-log_warning(QName, Fmt, Args) -> log(warning, QName, Fmt, Args).
-
-log(Level, QName, Fmt, Args) ->
- rabbit_log:log(mirroring, Level, "Mirrored ~s: " ++ Fmt,
- [rabbit_misc:rs(QName) | Args]).
+log_info (QName, Fmt, Args) ->
+ rabbit_log_mirroring:info("Mirrored ~s: " ++ Fmt,
+ [rabbit_misc:rs(QName) | Args]).
+log_warning(QName, Fmt, Args) ->
+ rabbit_log_mirroring:warning("Mirrored ~s: " ++ Fmt,
+ [rabbit_misc:rs(QName) | Args]).
store_updated_slaves(Q = #amqqueue{slave_pids = SPids,
sync_slave_pids = SSPids,
diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl
index 77914a00bf..6e2ed2a889 100644
--- a/src/rabbit_reader.erl
+++ b/src/rabbit_reader.erl
@@ -279,18 +279,20 @@ socket_error(Reason) when is_atom(Reason) ->
rabbit_log_connection:error("Error on AMQP connection ~p: ~s~n",
[self(), rabbit_misc:format_inet_error(Reason)]);
socket_error(Reason) ->
- Level =
- case Reason of
- {ssl_upgrade_error, closed} ->
- %% The socket was closed while upgrading to SSL.
- %% This is presumably a TCP healthcheck, so don't log
- %% it unless specified otherwise.
- debug;
- _ ->
- error
- end,
- rabbit_log:log(rabbit_log_connection, Level,
- "Error on AMQP connection ~p:~n~p~n", [self(), Reason]).
+ Fmt = "Error on AMQP connection ~p:~n~p~n",
+ Args = [self(), Reason],
+ case Reason of
+ %% The socket was closed while upgrading to SSL.
+ %% This is presumably a TCP healthcheck, so don't log
+ %% it unless specified otherwise.
+ {ssl_upgrade_error, closed} ->
+ %% Lager sinks (rabbit_log_connection)
+ %% are handled by the lager parse_transform.
+ %% Hence have to define the loglevel as a function call.
+ rabbit_log_connection:debug(Fmt, Args);
+ _ ->
+ rabbit_log_connection:error(Fmt, Args)
+ end.
inet_op(F) -> rabbit_misc:throw_on_error(inet_error, F).
@@ -402,31 +404,41 @@ log_connection_exception(Name, Ex) ->
log_connection_exception(Severity, Name, {heartbeat_timeout, TimeoutSec}) ->
%% Long line to avoid extra spaces and line breaks in log
- rabbit_log:log(rabbit_log_connection, Severity,
+ log_connection_exception_with_severity(Severity,
"closing AMQP connection ~p (~s):~n"
"missed heartbeats from client, timeout: ~ps~n",
[self(), Name, TimeoutSec]);
log_connection_exception(Severity, Name, {connection_closed_abruptly,
#v1{connection = #connection{user = #user{username = Username},
vhost = VHost}}}) ->
- rabbit_log:log(rabbit_log_connection, Severity, "closing AMQP connection ~p (~s, vhost: '~s', user: '~s'):~nclient unexpectedly closed TCP connection~n",
+ log_connection_exception_with_severity(Severity,
+ "closing AMQP connection ~p (~s, vhost: '~s', user: '~s'):~nclient unexpectedly closed TCP connection~n",
[self(), Name, VHost, Username]);
%% when client abruptly closes connection before connection.open/authentication/authorization
%% succeeded, don't log username and vhost as 'none'
log_connection_exception(Severity, Name, {connection_closed_abruptly, _}) ->
- rabbit_log:log(rabbit_log_connection, Severity, "closing AMQP connection ~p (~s):~nclient unexpectedly closed TCP connection~n",
+ log_connection_exception_with_severity(Severity,
+ "closing AMQP connection ~p (~s):~nclient unexpectedly closed TCP connection~n",
[self(), Name]);
%% old exception structure
log_connection_exception(Severity, Name, connection_closed_abruptly) ->
- rabbit_log:log(rabbit_log_connection, Severity,
+ log_connection_exception_with_severity(Severity,
"closing AMQP connection ~p (~s):~n"
"client unexpectedly closed TCP connection~n",
[self(), Name]);
log_connection_exception(Severity, Name, Ex) ->
- rabbit_log:log(rabbit_log_connection, Severity,
+ log_connection_exception_with_severity(Severity,
"closing AMQP connection ~p (~s):~n~p~n",
[self(), Name, Ex]).
+log_connection_exception_with_severity(Severity, Fmt, Args) ->
+ case Severity of
+ debug -> rabbit_log_connection:debug(Fmt, Args);
+ info -> rabbit_log_connection:info(Fmt, Args);
+ warning -> rabbit_log_connection:warning(Fmt, Args);
+ error -> rabbit_log_connection:warning(Fmt, Args)
+ end.
+
run({M, F, A}) ->
try apply(M, F, A)
catch {become, MFA} -> run(MFA)
@@ -475,13 +487,12 @@ mainloop(Deb, Buf, BufLen, State = #v1{sock = Sock,
%%
%% The goal is to not log TCP healthchecks (a connection
%% with no data received) unless specified otherwise.
- Level = case Recv of
- closed -> debug;
- _ -> info
- end,
- rabbit_log:log(rabbit_log_connection, Level,
- "accepting AMQP connection ~p (~s)~n",
- [self(), ConnName]);
+ Fmt = "accepting AMQP connection ~p (~s)~n",
+ Args = [self(), ConnName],
+ case Recv of
+ closed -> rabbit_log_connection:debug(Fmt, Args);
+ _ -> rabbit_log_connection:info(Fmt, Args)
+ end;
_ ->
ok
end,