Skip to content

Consistent logging #14232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Jul 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
175ba70
[skip ci] Remove rabbit_log and switch to LOG_ macros
mkuratczyk Jul 11, 2025
b6b766c
[skip ci] Replace logger: calls is LOG_ macros
mkuratczyk Jul 11, 2025
14fc15a
[skip ci] Remove rabbit_log_queue, replace with LOG_ macros
mkuratczyk Jul 11, 2025
1743881
[skip ci] Remove rabbit_log_channel and use LOG_ macros directly
mkuratczyk Jul 11, 2025
b7b30ce
[skip ci] Remove rabbit_log_mirroring
mkuratczyk Jul 11, 2025
5600138
[skip ci] Remove rabbit_log_prelaunch
mkuratczyk Jul 11, 2025
3ee8df9
[skip ci] Remove `pid` from logger process metadata
mkuratczyk Jul 11, 2025
ebe3f61
[skip ci] Remove rabbit_log_federation and use LOG_ macros
mkuratczyk Jul 11, 2025
8a05433
[skip ci] Remove rabbit_log_connection and use LOG_ macros
mkuratczyk Jul 11, 2025
ee100af
[skip ci] Remove rabbit_log_ldad and use LOG_ macros
mkuratczyk Jul 14, 2025
ad15dd3
[skip ci] Simplify logging around peer discovery
mkuratczyk Jul 14, 2025
8fb3ca1
[skip ci] Set logging domain to `?RMQLOG_DOMAIN_GLOBAL` on startup
mkuratczyk Jul 14, 2025
301f6e9
[skip ci] Remove redundant pid metadata in LOG_ macros
mkuratczyk Jul 15, 2025
84d52b5
[skip ci] Remove rabbit_log_shovel, use LOG_ macros directly
mkuratczyk Jul 15, 2025
24c3677
[skip ci] fix AMQP-1.0 DBG macro
mkuratczyk Jul 15, 2025
0cfab72
Fix AMQP-0.8 :)
mkuratczyk Jul 15, 2025
34d20d9
Remove incorrect include
mkuratczyk Jul 15, 2025
cc5c3c6
Add missing include
mkuratczyk Jul 15, 2025
8ffc991
Add missing includes
mkuratczyk Jul 15, 2025
d9103c9
Add exchange name back to the log
mkuratczyk Jul 15, 2025
11e51f5
Make dialyzer happy
mkuratczyk Jul 15, 2025
5cfb39d
rabbit_log -> logger in dynamic calls
mkuratczyk Jul 15, 2025
4a4b8be
Don't meck rabbit_log
mkuratczyk Jul 15, 2025
9ab4512
rabbit_log -> logger in CLI tests
mkuratczyk Jul 15, 2025
9b3f66c
Remove rabbit_log from Makefile
mkuratczyk Jul 15, 2025
bcc0622
rabbit_log -> logger in MQTT test
mkuratczyk Jul 15, 2025
e459859
Remove test for rabbit_log:log/4
mkuratczyk Jul 15, 2025
1e17455
[skip ci] Code formatting
mkuratczyk Jul 15, 2025
69b97b8
Trigger CI
mkuratczyk Jul 16, 2025
f6e718c
Re-introduce rabbit_log for backwards compatibility
mkuratczyk Jul 17, 2025
3ee82da
Updates for SQL filter changes
mkuratczyk Jul 18, 2025
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
9 changes: 5 additions & 4 deletions deps/amqp10_client/src/amqp10_client_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
-include("amqp10_client_internal.hrl").
-include_lib("amqp10_common/include/amqp10_framing.hrl").
-include_lib("amqp10_common/include/amqp10_types.hrl").
-include_lib("kernel/include/logger.hrl").

%% public API
-export([open/1,
Expand Down Expand Up @@ -247,8 +248,8 @@ hdr_sent(_EvtType, {protocol_header_received, 0, 1, 0, 0}, State) ->
end;
hdr_sent(_EvtType, {protocol_header_received, Protocol, Maj, Min,
Rev}, State) ->
logger:warning("Unsupported protocol version: ~b ~b.~b.~b",
[Protocol, Maj, Min, Rev]),
?LOG_WARNING("Unsupported protocol version: ~b ~b.~b.~b",
[Protocol, Maj, Min, Rev]),
{stop, normal, State};
hdr_sent({call, From}, begin_session,
#state{pending_session_reqs = PendingSessionReqs} = State) ->
Expand Down Expand Up @@ -342,8 +343,8 @@ opened(info, {'DOWN', MRef, process, _, _Info},
ok = notify_closed(Config, shutdown),
{stop, normal};
opened(_EvtType, Frame, State) ->
logger:warning("Unexpected connection frame ~tp when in state ~tp ",
[Frame, State]),
?LOG_WARNING("Unexpected connection frame ~tp when in state ~tp ",
[Frame, State]),
keep_state_and_data.

close_sent(_EvtType, heartbeat, _Data) ->
Expand Down
23 changes: 12 additions & 11 deletions deps/amqp10_client/src/amqp10_client_frame_reader.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

-include("amqp10_client_internal.hrl").
-include_lib("amqp10_common/include/amqp10_framing.hrl").
-include_lib("kernel/include/logger.hrl").

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
Expand Down Expand Up @@ -141,33 +142,33 @@ handle_event(info, {gun_ws, WsPid, StreamRef, WsFrame}, StateName,
{binary, Bin} ->
handle_socket_input(Bin, StateName, State);
close ->
logger:info("peer closed AMQP over WebSocket connection in state '~s'",
[StateName]),
?LOG_INFO("peer closed AMQP over WebSocket connection in state '~s'",
[StateName]),
{stop, normal, socket_closed(State)};
{close, ReasonStatusCode, ReasonUtf8} ->
logger:info("peer closed AMQP over WebSocket connection in state '~s', reason: ~b ~ts",
[StateName, ReasonStatusCode, ReasonUtf8]),
?LOG_INFO("peer closed AMQP over WebSocket connection in state '~s', reason: ~b ~ts",
[StateName, ReasonStatusCode, ReasonUtf8]),
{stop, {shutdown, {ReasonStatusCode, ReasonUtf8}}, socket_closed(State)}
end;
handle_event(info, {TcpError, _Sock, Reason}, StateName, State)
when TcpError == tcp_error orelse TcpError == ssl_error ->
logger:warning("AMQP 1.0 connection socket errored, connection state: '~ts', reason: '~tp'",
[StateName, Reason]),
?LOG_WARNING("AMQP 1.0 connection socket errored, connection state: '~ts', reason: '~tp'",
[StateName, Reason]),
{stop, {error, Reason}, socket_closed(State)};
handle_event(info, {TcpClosed, _}, StateName, State)
when TcpClosed == tcp_closed orelse TcpClosed == ssl_closed ->
logger:info("AMQP 1.0 connection socket was closed, connection state: '~ts'",
?LOG_INFO("AMQP 1.0 connection socket was closed, connection state: '~ts'",
[StateName]),
{stop, normal, socket_closed(State)};
handle_event(info, {gun_down, WsPid, _Proto, Reason, _Streams}, StateName,
#state{socket = {ws, WsPid, _StreamRef}} = State) ->
logger:warning("AMQP over WebSocket process ~p lost connection in state: '~s': ~p",
[WsPid, StateName, Reason]),
?LOG_WARNING("AMQP over WebSocket process ~p lost connection in state: '~s': ~p",
[WsPid, StateName, Reason]),
{stop, Reason, socket_closed(State)};
handle_event(info, {'DOWN', _Mref, process, WsPid, Reason}, StateName,
#state{socket = {ws, WsPid, _StreamRef}} = State) ->
logger:warning("AMQP over WebSocket process ~p terminated in state: '~s': ~p",
[WsPid, StateName, Reason]),
?LOG_WARNING("AMQP over WebSocket process ~p terminated in state: '~s': ~p",
[WsPid, StateName, Reason]),
{stop, Reason, socket_closed(State)};

handle_event(info, heartbeat, _StateName, #state{connection = Connection}) ->
Expand Down
2 changes: 1 addition & 1 deletion deps/amqp10_client/src/amqp10_client_internal.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

% -define(debug, true).
-ifdef(debug).
-define(DBG(F, A), error_logger:info_msg(F, A)).
-define(DBG(F, A), ?LOG_INFO(F, A)).
-else.
-define(DBG(F, A), ok).
-endif.
Expand Down
14 changes: 8 additions & 6 deletions deps/amqp10_client/src/amqp10_client_session.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
-include("amqp10_client_internal.hrl").
-include_lib("amqp10_common/include/amqp10_framing.hrl").
-include_lib("amqp10_common/include/amqp10_types.hrl").
-include_lib("kernel/include/logger.hrl").

%% Public API.
-export(['begin'/1,
Expand Down Expand Up @@ -434,7 +435,7 @@ mapped(cast, {Transfer0 = #'v1_0.transfer'{handle = {uint, InHandle}},
notify_credit_exhausted(Link3),
{keep_state, State};
{transfer_limit_exceeded, Link3, State} ->
logger:warning("transfer_limit_exceeded for link ~tp", [Link3]),
?LOG_WARNING("transfer_limit_exceeded for link ~tp", [Link3]),
Link = detach_with_error_cond(Link3,
State,
?V_1_0_LINK_ERROR_TRANSFER_LIMIT_EXCEEDED,
Expand All @@ -446,7 +447,7 @@ mapped(cast, {Transfer0 = #'v1_0.transfer'{handle = {uint, InHandle}},
io_lib:format(
"~s checksum error: expected ~b, actual ~b",
[FooterOpt, Expected, Actual])),
logger:warning("deteaching link ~tp due to ~s", [Link2, Description]),
?LOG_WARNING("deteaching link ~tp due to ~s", [Link2, Description]),
Link = detach_with_error_cond(Link2,
State0,
?V_1_0_AMQP_ERROR_DECODE_ERROR,
Expand Down Expand Up @@ -485,8 +486,8 @@ mapped(cast, #'v1_0.disposition'{role = true,

{keep_state, State#state{outgoing_unsettled = Unsettled}};
mapped(cast, Frame, State) ->
logger:warning("Unhandled session frame ~tp in state ~tp",
[Frame, State]),
?LOG_WARNING("Unhandled session frame ~tp in state ~tp",
[Frame, State]),
{keep_state, State};
mapped({call, From},
{transfer, _Transfer, _Sections},
Expand Down Expand Up @@ -566,8 +567,8 @@ mapped({call, From}, Msg, State) ->
{keep_state, State1, {reply, From, Reply}};

mapped(_EvtType, Msg, _State) ->
logger:warning("amqp10_session: unhandled msg in mapped state ~W",
[Msg, 10]),
?LOG_WARNING("amqp10_session: unhandled msg in mapped state ~W",
[Msg, 10]),
keep_state_and_data.

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

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-include_lib("kernel/include/logger.hrl").

handle_session_flow_test() ->
% see spec section: 2.5.6 for logic
Expand Down
5 changes: 0 additions & 5 deletions deps/amqp_client/include/amqp_client_internal.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@

-define(MAX_CHANNEL_NUMBER, 65535).

-define(LOG_DEBUG(Format), error_logger:info_msg(Format)).
-define(LOG_INFO(Format, Args), error_logger:info_msg(Format, Args)).
-define(LOG_WARN(Format, Args), error_logger:warning_msg(Format, Args)).
-define(LOG_ERR(Format, Args), error_logger:error_msg(Format, Args)).

-define(CLIENT_CAPABILITIES,
[{<<"publisher_confirms">>, bool, true},
{<<"exchange_exchange_bindings">>, bool, true},
Expand Down
25 changes: 13 additions & 12 deletions deps/amqp_client/src/amqp_channel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
-module(amqp_channel).

-include("amqp_client_internal.hrl").
-include_lib("kernel/include/logger.hrl").

-behaviour(gen_server).

Expand Down Expand Up @@ -514,7 +515,7 @@ handle_info({bump_credit, Msg}, State) ->
{noreply, State};
%% @private
handle_info(timed_out_flushing_channel, State) ->
?LOG_WARN("Channel (~tp) closing: timed out flushing while "
?LOG_WARNING("Channel (~tp) closing: timed out flushing while "
"connection closing", [self()]),
{stop, timed_out_flushing_channel, State};
%% @private
Expand All @@ -523,7 +524,7 @@ handle_info({'DOWN', _, process, ReturnHandler, shutdown},
{noreply, State#state{return_handler = none}};
handle_info({'DOWN', _, process, ReturnHandler, Reason},
State = #state{return_handler = {ReturnHandler, _Ref}}) ->
?LOG_WARN("Channel (~tp): Unregistering return handler ~tp because it died. "
?LOG_WARNING("Channel (~tp): Unregistering return handler ~tp because it died. "
"Reason: ~tp", [self(), ReturnHandler, Reason]),
{noreply, State#state{return_handler = none}};
%% @private
Expand All @@ -532,7 +533,7 @@ handle_info({'DOWN', _, process, ConfirmHandler, shutdown},
{noreply, State#state{confirm_handler = none}};
handle_info({'DOWN', _, process, ConfirmHandler, Reason},
State = #state{confirm_handler = {ConfirmHandler, _Ref}}) ->
?LOG_WARN("Channel (~tp): Unregistering confirm handler ~tp because it died. "
?LOG_WARNING("Channel (~tp): Unregistering confirm handler ~tp because it died. "
"Reason: ~tp", [self(), ConfirmHandler, Reason]),
{noreply, State#state{confirm_handler = none}};
%% @private
Expand All @@ -541,7 +542,7 @@ handle_info({'DOWN', _, process, FlowHandler, shutdown},
{noreply, State#state{flow_handler = none}};
handle_info({'DOWN', _, process, FlowHandler, Reason},
State = #state{flow_handler = {FlowHandler, _Ref}}) ->
?LOG_WARN("Channel (~tp): Unregistering flow handler ~tp because it died. "
?LOG_WARNING("Channel (~tp): Unregistering flow handler ~tp because it died. "
"Reason: ~tp", [self(), FlowHandler, Reason]),
{noreply, State#state{flow_handler = none}};
handle_info({'DOWN', _, process, QPid, _Reason}, State) ->
Expand Down Expand Up @@ -591,13 +592,13 @@ handle_method_to_server(Method, AmqpMsg, From, Sender, Flow,
{noreply, rpc_top_half(Method, build_content(AmqpMsg),
From, Sender, Flow, State1)};
{ok, none, BlockReply} ->
?LOG_WARN("Channel (~tp): discarding method ~tp in cast.~n"
?LOG_WARNING("Channel (~tp): discarding method ~tp in cast.~n"
"Reason: ~tp", [self(), Method, BlockReply]),
{noreply, State};
{ok, _, BlockReply} ->
{reply, BlockReply, State};
{{_, InvalidMethodMessage}, none, _} ->
?LOG_WARN("Channel (~tp): ignoring cast of ~tp method. " ++
?LOG_WARNING("Channel (~tp): ignoring cast of ~tp method. " ++
InvalidMethodMessage ++ "", [self(), Method]),
{noreply, State};
{{InvalidMethodReply, _}, _, _} ->
Expand Down Expand Up @@ -779,9 +780,9 @@ handle_method_from_server1(
#'basic.return'{} = BasicReturn, AmqpMsg,
State = #state{return_handler = ReturnHandler}) ->
_ = case ReturnHandler of
none -> ?LOG_WARN("Channel (~tp): received {~tp, ~tp} but there is "
"no return handler registered",
[self(), BasicReturn, AmqpMsg]);
none -> ?LOG_WARNING("Channel (~tp): received {~tp, ~tp} but there is "
"no return handler registered",
[self(), BasicReturn, AmqpMsg]);
{Pid, _Ref} -> Pid ! {BasicReturn, AmqpMsg}
end,
{noreply, State};
Expand All @@ -794,7 +795,7 @@ handle_method_from_server1(#'basic.ack'{} = BasicAck, none,
{noreply, update_confirm_set(BasicAck, State)};
handle_method_from_server1(#'basic.nack'{} = BasicNack, none,
#state{confirm_handler = none} = State) ->
?LOG_WARN("Channel (~tp): received ~tp but there is no "
?LOG_WARNING("Channel (~tp): received ~tp but there is no "
"confirm handler registered", [self(), BasicNack]),
{noreply, update_confirm_set(BasicNack, State)};
handle_method_from_server1(#'basic.nack'{} = BasicNack, none,
Expand Down Expand Up @@ -834,7 +835,7 @@ handle_connection_closing(CloseType, Reason,
handle_channel_exit(Reason = #amqp_error{name = ErrorName, explanation = Expl},
State = #state{connection = Connection, number = Number}) ->
%% Sent by rabbit_channel for hard errors in the direct case
?LOG_ERR("connection ~tp, channel ~tp - error:~n~tp",
?LOG_ERROR("connection ~tp, channel ~tp - error:~n~tp",
[Connection, Number, Reason]),
{true, Code, _} = ?PROTOCOL:lookup_amqp_exception(ErrorName),
ReportedReason = {server_initiated_close, Code, Expl},
Expand Down Expand Up @@ -930,7 +931,7 @@ server_misbehaved(#amqp_error{} = AmqpError, State = #state{number = Number}) ->
{0, _} ->
handle_shutdown({server_misbehaved, AmqpError}, State);
{_, Close} ->
?LOG_WARN("Channel (~tp) flushing and closing due to soft "
?LOG_WARNING("Channel (~tp) flushing and closing due to soft "
"error caused by the server ~tp", [self(), AmqpError]),
Self = self(),
spawn(fun () -> call(Self, Close) end),
Expand Down
1 change: 1 addition & 0 deletions deps/amqp_client/src/amqp_channels_manager.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
-module(amqp_channels_manager).

-include("amqp_client_internal.hrl").
-include_lib("kernel/include/logger.hrl").

-behaviour(gen_server).

Expand Down
3 changes: 2 additions & 1 deletion deps/amqp_client/src/amqp_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
-module(amqp_connection).

-include("amqp_client_internal.hrl").
-include_lib("kernel/include/logger.hrl").

-export([open_channel/1, open_channel/2, open_channel/3, register_blocked_handler/2]).
-export([start/1, start/2, close/1, close/2, close/3, close/4]).
Expand Down Expand Up @@ -427,7 +428,7 @@ maybe_update_call_timeout(BaseTimeout, CallTimeout)
ok;
maybe_update_call_timeout(BaseTimeout, CallTimeout) ->
EffectiveSafeCallTimeout = amqp_util:safe_call_timeout(BaseTimeout),
?LOG_WARN("AMQP 0-9-1 client call timeout was ~tp ms, is updated to a safe effective "
?LOG_WARNING("AMQP 0-9-1 client call timeout was ~tp ms, is updated to a safe effective "
"value of ~tp ms", [CallTimeout, EffectiveSafeCallTimeout]),
amqp_util:update_call_timeout(EffectiveSafeCallTimeout),
ok.
Expand Down
1 change: 1 addition & 0 deletions deps/amqp_client/src/amqp_direct_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
-module(amqp_direct_connection).

-include("amqp_client_internal.hrl").
-include_lib("kernel/include/logger.hrl").

-behaviour(amqp_gen_connection).

Expand Down
15 changes: 8 additions & 7 deletions deps/amqp_client/src/amqp_gen_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
-module(amqp_gen_connection).

-include("amqp_client_internal.hrl").
-include_lib("kernel/include/logger.hrl").

-behaviour(gen_server).

Expand Down Expand Up @@ -191,8 +192,8 @@ handle_cast(channels_terminated, State) ->
handle_cast({hard_error_in_channel, _Pid, Reason}, State) ->
server_initiated_close(Reason, State);
handle_cast({channel_internal_error, Pid, Reason}, State) ->
?LOG_WARN("Connection (~tp) closing: internal error in channel (~tp): ~tp",
[self(), Pid, Reason]),
?LOG_WARNING("Connection (~tp) closing: internal error in channel (~tp): ~tp",
[self(), Pid, Reason]),
internal_error(Pid, Reason, State);
handle_cast({server_misbehaved, AmqpError}, State) ->
server_misbehaved_close(AmqpError, State);
Expand All @@ -205,12 +206,12 @@ handle_cast({register_blocked_handler, HandlerPid}, State) ->
%% @private
handle_info({'DOWN', _, process, BlockHandler, Reason},
State = #state{block_handler = {BlockHandler, _Ref}}) ->
?LOG_WARN("Connection (~tp): Unregistering connection.{blocked,unblocked} handler ~tp because it died. "
?LOG_WARNING("Connection (~tp): Unregistering connection.{blocked,unblocked} handler ~tp because it died. "
"Reason: ~tp", [self(), BlockHandler, Reason]),
{noreply, State#state{block_handler = none}};
handle_info({'EXIT', BlockHandler, Reason},
State = #state{block_handler = {BlockHandler, Ref}}) ->
?LOG_WARN("Connection (~tp): Unregistering connection.{blocked,unblocked} handler ~tp because it died. "
?LOG_WARNING("Connection (~tp): Unregistering connection.{blocked,unblocked} handler ~tp because it died. "
"Reason: ~tp", [self(), BlockHandler, Reason]),
erlang:demonitor(Ref, [flush]),
{noreply, State#state{block_handler = none}};
Expand Down Expand Up @@ -316,14 +317,14 @@ internal_error(Pid, Reason, State) ->
State).

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

server_misbehaved_close(AmqpError, State) ->
?LOG_WARN("Connection (~tp) closing: server misbehaved: ~tp",
[self(), AmqpError]),
?LOG_WARNING("Connection (~tp) closing: server misbehaved: ~tp",
[self(), AmqpError]),
{0, Close} = rabbit_binary_generator:map_exception(0, AmqpError, ?PROTOCOL),
set_closing_state(abrupt, #closing{reason = server_misbehaved,
close = Close}, State).
Expand Down
3 changes: 2 additions & 1 deletion deps/amqp_client/src/amqp_ssl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
-include("amqp_client_internal.hrl").

-include_lib("public_key/include/public_key.hrl").
-include_lib("kernel/include/logger.hrl").

-export([maybe_enhance_ssl_options/1,
verify_fun/3]).
Expand Down Expand Up @@ -51,7 +52,7 @@ maybe_add_verify1(Options) ->
% NB: user has explicitly set 'verify'
Options;
_ ->
?LOG_WARN("Connection (~tp): certificate chain verification is not enabled for this TLS connection. "
?LOG_WARNING("Connection (~tp): certificate chain verification is not enabled for this TLS connection. "
"Please see https://rabbitmq.com/ssl.html for more information.", [self()]),
Options
end.
Expand Down
Loading
Loading