Skip to content

Commit febb580

Browse files
authored
Merge pull request #14232 from rabbitmq/consistent-logging
Consistent logging
2 parents 310e812 + 3ee82da commit febb580

File tree

217 files changed

+1805
-2417
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

217 files changed

+1805
-2417
lines changed

deps/amqp10_client/src/amqp10_client_connection.erl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
-include("amqp10_client_internal.hrl").
1313
-include_lib("amqp10_common/include/amqp10_framing.hrl").
1414
-include_lib("amqp10_common/include/amqp10_types.hrl").
15+
-include_lib("kernel/include/logger.hrl").
1516

1617
%% public API
1718
-export([open/1,
@@ -247,8 +248,8 @@ hdr_sent(_EvtType, {protocol_header_received, 0, 1, 0, 0}, State) ->
247248
end;
248249
hdr_sent(_EvtType, {protocol_header_received, Protocol, Maj, Min,
249250
Rev}, State) ->
250-
logger:warning("Unsupported protocol version: ~b ~b.~b.~b",
251-
[Protocol, Maj, Min, Rev]),
251+
?LOG_WARNING("Unsupported protocol version: ~b ~b.~b.~b",
252+
[Protocol, Maj, Min, Rev]),
252253
{stop, normal, State};
253254
hdr_sent({call, From}, begin_session,
254255
#state{pending_session_reqs = PendingSessionReqs} = State) ->
@@ -342,8 +343,8 @@ opened(info, {'DOWN', MRef, process, _, _Info},
342343
ok = notify_closed(Config, shutdown),
343344
{stop, normal};
344345
opened(_EvtType, Frame, State) ->
345-
logger:warning("Unexpected connection frame ~tp when in state ~tp ",
346-
[Frame, State]),
346+
?LOG_WARNING("Unexpected connection frame ~tp when in state ~tp ",
347+
[Frame, State]),
347348
keep_state_and_data.
348349

349350
close_sent(_EvtType, heartbeat, _Data) ->

deps/amqp10_client/src/amqp10_client_frame_reader.erl

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
-include("amqp10_client_internal.hrl").
1212
-include_lib("amqp10_common/include/amqp10_framing.hrl").
13+
-include_lib("kernel/include/logger.hrl").
1314

1415
-ifdef(TEST).
1516
-include_lib("eunit/include/eunit.hrl").
@@ -141,33 +142,33 @@ handle_event(info, {gun_ws, WsPid, StreamRef, WsFrame}, StateName,
141142
{binary, Bin} ->
142143
handle_socket_input(Bin, StateName, State);
143144
close ->
144-
logger:info("peer closed AMQP over WebSocket connection in state '~s'",
145-
[StateName]),
145+
?LOG_INFO("peer closed AMQP over WebSocket connection in state '~s'",
146+
[StateName]),
146147
{stop, normal, socket_closed(State)};
147148
{close, ReasonStatusCode, ReasonUtf8} ->
148-
logger:info("peer closed AMQP over WebSocket connection in state '~s', reason: ~b ~ts",
149-
[StateName, ReasonStatusCode, ReasonUtf8]),
149+
?LOG_INFO("peer closed AMQP over WebSocket connection in state '~s', reason: ~b ~ts",
150+
[StateName, ReasonStatusCode, ReasonUtf8]),
150151
{stop, {shutdown, {ReasonStatusCode, ReasonUtf8}}, socket_closed(State)}
151152
end;
152153
handle_event(info, {TcpError, _Sock, Reason}, StateName, State)
153154
when TcpError == tcp_error orelse TcpError == ssl_error ->
154-
logger:warning("AMQP 1.0 connection socket errored, connection state: '~ts', reason: '~tp'",
155-
[StateName, Reason]),
155+
?LOG_WARNING("AMQP 1.0 connection socket errored, connection state: '~ts', reason: '~tp'",
156+
[StateName, Reason]),
156157
{stop, {error, Reason}, socket_closed(State)};
157158
handle_event(info, {TcpClosed, _}, StateName, State)
158159
when TcpClosed == tcp_closed orelse TcpClosed == ssl_closed ->
159-
logger:info("AMQP 1.0 connection socket was closed, connection state: '~ts'",
160+
?LOG_INFO("AMQP 1.0 connection socket was closed, connection state: '~ts'",
160161
[StateName]),
161162
{stop, normal, socket_closed(State)};
162163
handle_event(info, {gun_down, WsPid, _Proto, Reason, _Streams}, StateName,
163164
#state{socket = {ws, WsPid, _StreamRef}} = State) ->
164-
logger:warning("AMQP over WebSocket process ~p lost connection in state: '~s': ~p",
165-
[WsPid, StateName, Reason]),
165+
?LOG_WARNING("AMQP over WebSocket process ~p lost connection in state: '~s': ~p",
166+
[WsPid, StateName, Reason]),
166167
{stop, Reason, socket_closed(State)};
167168
handle_event(info, {'DOWN', _Mref, process, WsPid, Reason}, StateName,
168169
#state{socket = {ws, WsPid, _StreamRef}} = State) ->
169-
logger:warning("AMQP over WebSocket process ~p terminated in state: '~s': ~p",
170-
[WsPid, StateName, Reason]),
170+
?LOG_WARNING("AMQP over WebSocket process ~p terminated in state: '~s': ~p",
171+
[WsPid, StateName, Reason]),
171172
{stop, Reason, socket_closed(State)};
172173

173174
handle_event(info, heartbeat, _StateName, #state{connection = Connection}) ->

deps/amqp10_client/src/amqp10_client_internal.hrl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
% -define(debug, true).
1414
-ifdef(debug).
15-
-define(DBG(F, A), error_logger:info_msg(F, A)).
15+
-define(DBG(F, A), ?LOG_INFO(F, A)).
1616
-else.
1717
-define(DBG(F, A), ok).
1818
-endif.

deps/amqp10_client/src/amqp10_client_session.erl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
-include("amqp10_client_internal.hrl").
1313
-include_lib("amqp10_common/include/amqp10_framing.hrl").
1414
-include_lib("amqp10_common/include/amqp10_types.hrl").
15+
-include_lib("kernel/include/logger.hrl").
1516

1617
%% Public API.
1718
-export(['begin'/1,
@@ -434,7 +435,7 @@ mapped(cast, {Transfer0 = #'v1_0.transfer'{handle = {uint, InHandle}},
434435
notify_credit_exhausted(Link3),
435436
{keep_state, State};
436437
{transfer_limit_exceeded, Link3, State} ->
437-
logger:warning("transfer_limit_exceeded for link ~tp", [Link3]),
438+
?LOG_WARNING("transfer_limit_exceeded for link ~tp", [Link3]),
438439
Link = detach_with_error_cond(Link3,
439440
State,
440441
?V_1_0_LINK_ERROR_TRANSFER_LIMIT_EXCEEDED,
@@ -446,7 +447,7 @@ mapped(cast, {Transfer0 = #'v1_0.transfer'{handle = {uint, InHandle}},
446447
io_lib:format(
447448
"~s checksum error: expected ~b, actual ~b",
448449
[FooterOpt, Expected, Actual])),
449-
logger:warning("deteaching link ~tp due to ~s", [Link2, Description]),
450+
?LOG_WARNING("deteaching link ~tp due to ~s", [Link2, Description]),
450451
Link = detach_with_error_cond(Link2,
451452
State0,
452453
?V_1_0_AMQP_ERROR_DECODE_ERROR,
@@ -485,8 +486,8 @@ mapped(cast, #'v1_0.disposition'{role = true,
485486

486487
{keep_state, State#state{outgoing_unsettled = Unsettled}};
487488
mapped(cast, Frame, State) ->
488-
logger:warning("Unhandled session frame ~tp in state ~tp",
489-
[Frame, State]),
489+
?LOG_WARNING("Unhandled session frame ~tp in state ~tp",
490+
[Frame, State]),
490491
{keep_state, State};
491492
mapped({call, From},
492493
{transfer, _Transfer, _Sections},
@@ -566,8 +567,8 @@ mapped({call, From}, Msg, State) ->
566567
{keep_state, State1, {reply, From, Reply}};
567568

568569
mapped(_EvtType, Msg, _State) ->
569-
logger:warning("amqp10_session: unhandled msg in mapped state ~W",
570-
[Msg, 10]),
570+
?LOG_WARNING("amqp10_session: unhandled msg in mapped state ~W",
571+
[Msg, 10]),
571572
keep_state_and_data.
572573

573574
end_sent(_EvtType, #'v1_0.end'{} = End, State) ->
@@ -1375,6 +1376,7 @@ format_status(Status = #{data := Data0}) ->
13751376

13761377
-ifdef(TEST).
13771378
-include_lib("eunit/include/eunit.hrl").
1379+
-include_lib("kernel/include/logger.hrl").
13781380

13791381
handle_session_flow_test() ->
13801382
% see spec section: 2.5.6 for logic

deps/amqp_client/include/amqp_client_internal.hrl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414

1515
-define(MAX_CHANNEL_NUMBER, 65535).
1616

17-
-define(LOG_DEBUG(Format), error_logger:info_msg(Format)).
18-
-define(LOG_INFO(Format, Args), error_logger:info_msg(Format, Args)).
19-
-define(LOG_WARN(Format, Args), error_logger:warning_msg(Format, Args)).
20-
-define(LOG_ERR(Format, Args), error_logger:error_msg(Format, Args)).
21-
2217
-define(CLIENT_CAPABILITIES,
2318
[{<<"publisher_confirms">>, bool, true},
2419
{<<"exchange_exchange_bindings">>, bool, true},

deps/amqp_client/src/amqp_channel.erl

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
-module(amqp_channel).
5555

5656
-include("amqp_client_internal.hrl").
57+
-include_lib("kernel/include/logger.hrl").
5758

5859
-behaviour(gen_server).
5960

@@ -514,7 +515,7 @@ handle_info({bump_credit, Msg}, State) ->
514515
{noreply, State};
515516
%% @private
516517
handle_info(timed_out_flushing_channel, State) ->
517-
?LOG_WARN("Channel (~tp) closing: timed out flushing while "
518+
?LOG_WARNING("Channel (~tp) closing: timed out flushing while "
518519
"connection closing", [self()]),
519520
{stop, timed_out_flushing_channel, State};
520521
%% @private
@@ -523,7 +524,7 @@ handle_info({'DOWN', _, process, ReturnHandler, shutdown},
523524
{noreply, State#state{return_handler = none}};
524525
handle_info({'DOWN', _, process, ReturnHandler, Reason},
525526
State = #state{return_handler = {ReturnHandler, _Ref}}) ->
526-
?LOG_WARN("Channel (~tp): Unregistering return handler ~tp because it died. "
527+
?LOG_WARNING("Channel (~tp): Unregistering return handler ~tp because it died. "
527528
"Reason: ~tp", [self(), ReturnHandler, Reason]),
528529
{noreply, State#state{return_handler = none}};
529530
%% @private
@@ -532,7 +533,7 @@ handle_info({'DOWN', _, process, ConfirmHandler, shutdown},
532533
{noreply, State#state{confirm_handler = none}};
533534
handle_info({'DOWN', _, process, ConfirmHandler, Reason},
534535
State = #state{confirm_handler = {ConfirmHandler, _Ref}}) ->
535-
?LOG_WARN("Channel (~tp): Unregistering confirm handler ~tp because it died. "
536+
?LOG_WARNING("Channel (~tp): Unregistering confirm handler ~tp because it died. "
536537
"Reason: ~tp", [self(), ConfirmHandler, Reason]),
537538
{noreply, State#state{confirm_handler = none}};
538539
%% @private
@@ -541,7 +542,7 @@ handle_info({'DOWN', _, process, FlowHandler, shutdown},
541542
{noreply, State#state{flow_handler = none}};
542543
handle_info({'DOWN', _, process, FlowHandler, Reason},
543544
State = #state{flow_handler = {FlowHandler, _Ref}}) ->
544-
?LOG_WARN("Channel (~tp): Unregistering flow handler ~tp because it died. "
545+
?LOG_WARNING("Channel (~tp): Unregistering flow handler ~tp because it died. "
545546
"Reason: ~tp", [self(), FlowHandler, Reason]),
546547
{noreply, State#state{flow_handler = none}};
547548
handle_info({'DOWN', _, process, QPid, _Reason}, State) ->
@@ -591,13 +592,13 @@ handle_method_to_server(Method, AmqpMsg, From, Sender, Flow,
591592
{noreply, rpc_top_half(Method, build_content(AmqpMsg),
592593
From, Sender, Flow, State1)};
593594
{ok, none, BlockReply} ->
594-
?LOG_WARN("Channel (~tp): discarding method ~tp in cast.~n"
595+
?LOG_WARNING("Channel (~tp): discarding method ~tp in cast.~n"
595596
"Reason: ~tp", [self(), Method, BlockReply]),
596597
{noreply, State};
597598
{ok, _, BlockReply} ->
598599
{reply, BlockReply, State};
599600
{{_, InvalidMethodMessage}, none, _} ->
600-
?LOG_WARN("Channel (~tp): ignoring cast of ~tp method. " ++
601+
?LOG_WARNING("Channel (~tp): ignoring cast of ~tp method. " ++
601602
InvalidMethodMessage ++ "", [self(), Method]),
602603
{noreply, State};
603604
{{InvalidMethodReply, _}, _, _} ->
@@ -779,9 +780,9 @@ handle_method_from_server1(
779780
#'basic.return'{} = BasicReturn, AmqpMsg,
780781
State = #state{return_handler = ReturnHandler}) ->
781782
_ = case ReturnHandler of
782-
none -> ?LOG_WARN("Channel (~tp): received {~tp, ~tp} but there is "
783-
"no return handler registered",
784-
[self(), BasicReturn, AmqpMsg]);
783+
none -> ?LOG_WARNING("Channel (~tp): received {~tp, ~tp} but there is "
784+
"no return handler registered",
785+
[self(), BasicReturn, AmqpMsg]);
785786
{Pid, _Ref} -> Pid ! {BasicReturn, AmqpMsg}
786787
end,
787788
{noreply, State};
@@ -794,7 +795,7 @@ handle_method_from_server1(#'basic.ack'{} = BasicAck, none,
794795
{noreply, update_confirm_set(BasicAck, State)};
795796
handle_method_from_server1(#'basic.nack'{} = BasicNack, none,
796797
#state{confirm_handler = none} = State) ->
797-
?LOG_WARN("Channel (~tp): received ~tp but there is no "
798+
?LOG_WARNING("Channel (~tp): received ~tp but there is no "
798799
"confirm handler registered", [self(), BasicNack]),
799800
{noreply, update_confirm_set(BasicNack, State)};
800801
handle_method_from_server1(#'basic.nack'{} = BasicNack, none,
@@ -834,7 +835,7 @@ handle_connection_closing(CloseType, Reason,
834835
handle_channel_exit(Reason = #amqp_error{name = ErrorName, explanation = Expl},
835836
State = #state{connection = Connection, number = Number}) ->
836837
%% Sent by rabbit_channel for hard errors in the direct case
837-
?LOG_ERR("connection ~tp, channel ~tp - error:~n~tp",
838+
?LOG_ERROR("connection ~tp, channel ~tp - error:~n~tp",
838839
[Connection, Number, Reason]),
839840
{true, Code, _} = ?PROTOCOL:lookup_amqp_exception(ErrorName),
840841
ReportedReason = {server_initiated_close, Code, Expl},
@@ -930,7 +931,7 @@ server_misbehaved(#amqp_error{} = AmqpError, State = #state{number = Number}) ->
930931
{0, _} ->
931932
handle_shutdown({server_misbehaved, AmqpError}, State);
932933
{_, Close} ->
933-
?LOG_WARN("Channel (~tp) flushing and closing due to soft "
934+
?LOG_WARNING("Channel (~tp) flushing and closing due to soft "
934935
"error caused by the server ~tp", [self(), AmqpError]),
935936
Self = self(),
936937
spawn(fun () -> call(Self, Close) end),

deps/amqp_client/src/amqp_channels_manager.erl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
-module(amqp_channels_manager).
1010

1111
-include("amqp_client_internal.hrl").
12+
-include_lib("kernel/include/logger.hrl").
1213

1314
-behaviour(gen_server).
1415

deps/amqp_client/src/amqp_connection.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
-module(amqp_connection).
6060

6161
-include("amqp_client_internal.hrl").
62+
-include_lib("kernel/include/logger.hrl").
6263

6364
-export([open_channel/1, open_channel/2, open_channel/3, register_blocked_handler/2]).
6465
-export([start/1, start/2, close/1, close/2, close/3, close/4]).
@@ -427,7 +428,7 @@ maybe_update_call_timeout(BaseTimeout, CallTimeout)
427428
ok;
428429
maybe_update_call_timeout(BaseTimeout, CallTimeout) ->
429430
EffectiveSafeCallTimeout = amqp_util:safe_call_timeout(BaseTimeout),
430-
?LOG_WARN("AMQP 0-9-1 client call timeout was ~tp ms, is updated to a safe effective "
431+
?LOG_WARNING("AMQP 0-9-1 client call timeout was ~tp ms, is updated to a safe effective "
431432
"value of ~tp ms", [CallTimeout, EffectiveSafeCallTimeout]),
432433
amqp_util:update_call_timeout(EffectiveSafeCallTimeout),
433434
ok.

deps/amqp_client/src/amqp_direct_connection.erl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
-module(amqp_direct_connection).
1010

1111
-include("amqp_client_internal.hrl").
12+
-include_lib("kernel/include/logger.hrl").
1213

1314
-behaviour(amqp_gen_connection).
1415

deps/amqp_client/src/amqp_gen_connection.erl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
-module(amqp_gen_connection).
1010

1111
-include("amqp_client_internal.hrl").
12+
-include_lib("kernel/include/logger.hrl").
1213

1314
-behaviour(gen_server).
1415

@@ -191,8 +192,8 @@ handle_cast(channels_terminated, State) ->
191192
handle_cast({hard_error_in_channel, _Pid, Reason}, State) ->
192193
server_initiated_close(Reason, State);
193194
handle_cast({channel_internal_error, Pid, Reason}, State) ->
194-
?LOG_WARN("Connection (~tp) closing: internal error in channel (~tp): ~tp",
195-
[self(), Pid, Reason]),
195+
?LOG_WARNING("Connection (~tp) closing: internal error in channel (~tp): ~tp",
196+
[self(), Pid, Reason]),
196197
internal_error(Pid, Reason, State);
197198
handle_cast({server_misbehaved, AmqpError}, State) ->
198199
server_misbehaved_close(AmqpError, State);
@@ -205,12 +206,12 @@ handle_cast({register_blocked_handler, HandlerPid}, State) ->
205206
%% @private
206207
handle_info({'DOWN', _, process, BlockHandler, Reason},
207208
State = #state{block_handler = {BlockHandler, _Ref}}) ->
208-
?LOG_WARN("Connection (~tp): Unregistering connection.{blocked,unblocked} handler ~tp because it died. "
209+
?LOG_WARNING("Connection (~tp): Unregistering connection.{blocked,unblocked} handler ~tp because it died. "
209210
"Reason: ~tp", [self(), BlockHandler, Reason]),
210211
{noreply, State#state{block_handler = none}};
211212
handle_info({'EXIT', BlockHandler, Reason},
212213
State = #state{block_handler = {BlockHandler, Ref}}) ->
213-
?LOG_WARN("Connection (~tp): Unregistering connection.{blocked,unblocked} handler ~tp because it died. "
214+
?LOG_WARNING("Connection (~tp): Unregistering connection.{blocked,unblocked} handler ~tp because it died. "
214215
"Reason: ~tp", [self(), BlockHandler, Reason]),
215216
erlang:demonitor(Ref, [flush]),
216217
{noreply, State#state{block_handler = none}};
@@ -316,14 +317,14 @@ internal_error(Pid, Reason, State) ->
316317
State).
317318

318319
server_initiated_close(Close, State) ->
319-
?LOG_WARN("Connection (~tp) closing: received hard error ~tp "
320+
?LOG_WARNING("Connection (~tp) closing: received hard error ~tp "
320321
"from server", [self(), Close]),
321322
set_closing_state(abrupt, #closing{reason = server_initiated_close,
322323
close = Close}, State).
323324

324325
server_misbehaved_close(AmqpError, State) ->
325-
?LOG_WARN("Connection (~tp) closing: server misbehaved: ~tp",
326-
[self(), AmqpError]),
326+
?LOG_WARNING("Connection (~tp) closing: server misbehaved: ~tp",
327+
[self(), AmqpError]),
327328
{0, Close} = rabbit_binary_generator:map_exception(0, AmqpError, ?PROTOCOL),
328329
set_closing_state(abrupt, #closing{reason = server_misbehaved,
329330
close = Close}, State).

0 commit comments

Comments
 (0)