Skip to content

Switch from Lager to the new Erlang Logger API for logging #2861

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 4 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions deps/amqp10_client/src/amqp10_client_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ hdr_sent(_EvtType, {protocol_header_received, 0, 1, 0, 0}, State) ->
end;
hdr_sent(_EvtType, {protocol_header_received, Protocol, Maj, Min,
Rev}, State) ->
error_logger:warning_msg("Unsupported protocol version: ~b ~b.~b.~b~n",
logger:warning("Unsupported protocol version: ~b ~b.~b.~b",
[Protocol, Maj, Min, Rev]),
{stop, normal, State};
hdr_sent({call, From}, begin_session,
Expand Down Expand Up @@ -291,7 +291,7 @@ opened(info, {'DOWN', MRef, _, _, _Info},
ok = notify_closed(Config, shutdown),
{stop, normal, State};
opened(_EvtType, Frame, State) ->
error_logger:warning_msg("Unexpected connection frame ~p when in state ~p ~n",
logger:warning("Unexpected connection frame ~p when in state ~p ",
[Frame, State]),
{keep_state, State}.

Expand Down Expand Up @@ -367,15 +367,15 @@ send_open(#state{socket = Socket, config = Config}) ->
end,
Encoded = amqp10_framing:encode_bin(Open),
Frame = amqp10_binary_generator:build_frame(0, Encoded),
?DBG("CONN <- ~p~n", [Open]),
?DBG("CONN <- ~p", [Open]),
socket_send(Socket, Frame).


send_close(#state{socket = Socket}, _Reason) ->
Close = #'v1_0.close'{},
Encoded = amqp10_framing:encode_bin(Close),
Frame = amqp10_binary_generator:build_frame(0, Encoded),
?DBG("CONN <- ~p~n", [Close]),
?DBG("CONN <- ~p", [Close]),
Ret = socket_send(Socket, Frame),
case Ret of
ok -> _ =
Expand All @@ -397,7 +397,7 @@ send_sasl_init(State, {plain, User, Pass}) ->
send(Record, FrameType, #state{socket = Socket}) ->
Encoded = amqp10_framing:encode_bin(Record),
Frame = amqp10_binary_generator:build_frame(0, FrameType, Encoded),
?DBG("CONN <- ~p~n", [Record]),
?DBG("CONN <- ~p", [Record]),
socket_send(Socket, Frame).

send_heartbeat(#state{socket = Socket}) ->
Expand Down
10 changes: 5 additions & 5 deletions deps/amqp10_client/src/amqp10_client_frame_reader.erl
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,16 @@ handle_event(info, {Tcp, _, Packet}, StateName, #state{buffer = Buffer} = State)

handle_event(info, {TcpError, _, Reason}, StateName, State)
when TcpError == tcp_error orelse TcpError == ssl_error ->
error_logger:warning_msg("AMQP 1.0 connection socket errored, connection state: '~s', reason: '~p'~n",
[StateName, Reason]),
logger:warning("AMQP 1.0 connection socket errored, connection state: '~s', reason: '~p'",
[StateName, Reason]),
State1 = State#state{socket = undefined,
buffer = <<>>,
frame_state = undefined},
{stop, {error, Reason}, State1};
handle_event(info, {TcpClosed, _}, StateName, State)
when TcpClosed == tcp_closed orelse TcpClosed == ssl_closed ->
error_logger:warning_msg("AMQP 1.0 connection socket was closed, connection state: '~s'~n",
[StateName]),
logger:warning("AMQP 1.0 connection socket was closed, connection state: '~s'",
[StateName]),
State1 = State#state{socket = undefined,
buffer = <<>>,
frame_state = undefined},
Expand Down Expand Up @@ -279,7 +279,7 @@ defer_heartbeat_timer(State) -> State.
route_frame(Channel, FrameType, {Performative, Payload} = Frame, State0) ->
{DestinationPid, State} = find_destination(Channel, FrameType, Performative,
State0),
?DBG("FRAME -> ~p ~p~n ~p~n", [Channel, DestinationPid, Performative]),
?DBG("FRAME -> ~p ~p~n ~p", [Channel, DestinationPid, Performative]),
case Payload of
<<>> -> ok = gen_statem:cast(DestinationPid, Performative);
_ -> ok = gen_statem:cast(DestinationPid, Frame)
Expand Down
6 changes: 3 additions & 3 deletions deps/amqp10_client/src/amqp10_client_session.erl
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ mapped(cast, {#'v1_0.transfer'{handle = {uint, InHandle},
ok = notify_link(Link, credit_exhausted),
{next_state, mapped, State};
{transfer_limit_exceeded, State} ->
error_logger:info_msg("transfer_limit_exceeded for link ~p~n", [Link]),
logger:warning("transfer_limit_exceeded for link ~p", [Link]),
Link1 = detach_with_error_cond(Link, State,
?V_1_0_LINK_ERROR_TRANSFER_LIMIT_EXCEEDED),
{next_state, mapped, update_link(Link1, State)}
Expand Down Expand Up @@ -403,7 +403,7 @@ mapped(cast, #'v1_0.disposition'{role = true, settled = true, first = {uint, Fir

{next_state, mapped, State#state{unsettled = Unsettled}};
mapped(cast, Frame, State) ->
error_logger:warning_msg("Unhandled session frame ~p in state ~p~n",
logger:warning("Unhandled session frame ~p in state ~p",
[Frame, State]),
{next_state, mapped, State};
mapped({call, From},
Expand Down Expand Up @@ -490,7 +490,7 @@ mapped({call, From}, Msg, State) ->
{keep_state, State1, [{reply, From, Reply}]};

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

Expand Down
22 changes: 11 additions & 11 deletions deps/amqp_client/src/amqp_channel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ handle_info({bump_credit, Msg}, State) ->
%% @private
handle_info(timed_out_flushing_channel, State) ->
?LOG_WARN("Channel (~p) closing: timed out flushing while "
"connection closing~n", [self()]),
"connection closing", [self()]),
{stop, timed_out_flushing_channel, State};
%% @private
handle_info({'DOWN', _, process, ReturnHandler, shutdown},
Expand All @@ -520,7 +520,7 @@ handle_info({'DOWN', _, process, ReturnHandler, shutdown},
handle_info({'DOWN', _, process, ReturnHandler, Reason},
State = #state{return_handler = {ReturnHandler, _Ref}}) ->
?LOG_WARN("Channel (~p): Unregistering return handler ~p because it died. "
"Reason: ~p~n", [self(), ReturnHandler, Reason]),
"Reason: ~p", [self(), ReturnHandler, Reason]),
{noreply, State#state{return_handler = none}};
%% @private
handle_info({'DOWN', _, process, ConfirmHandler, shutdown},
Expand All @@ -529,7 +529,7 @@ handle_info({'DOWN', _, process, ConfirmHandler, shutdown},
handle_info({'DOWN', _, process, ConfirmHandler, Reason},
State = #state{confirm_handler = {ConfirmHandler, _Ref}}) ->
?LOG_WARN("Channel (~p): Unregistering confirm handler ~p because it died. "
"Reason: ~p~n", [self(), ConfirmHandler, Reason]),
"Reason: ~p", [self(), ConfirmHandler, Reason]),
{noreply, State#state{confirm_handler = none}};
%% @private
handle_info({'DOWN', _, process, FlowHandler, shutdown},
Expand All @@ -538,7 +538,7 @@ handle_info({'DOWN', _, process, FlowHandler, shutdown},
handle_info({'DOWN', _, process, FlowHandler, Reason},
State = #state{flow_handler = {FlowHandler, _Ref}}) ->
?LOG_WARN("Channel (~p): Unregistering flow handler ~p because it died. "
"Reason: ~p~n", [self(), FlowHandler, Reason]),
"Reason: ~p", [self(), FlowHandler, Reason]),
{noreply, State#state{flow_handler = none}};
handle_info({'DOWN', _, process, QPid, _Reason}, State) ->
rabbit_amqqueue_common:notify_sent_queue_down(QPid),
Expand Down Expand Up @@ -588,13 +588,13 @@ handle_method_to_server(Method, AmqpMsg, From, Sender, Flow,
From, Sender, Flow, State1)};
{ok, none, BlockReply} ->
?LOG_WARN("Channel (~p): discarding method ~p in cast.~n"
"Reason: ~p~n", [self(), Method, BlockReply]),
"Reason: ~p", [self(), Method, BlockReply]),
{noreply, State};
{ok, _, BlockReply} ->
{reply, BlockReply, State};
{{_, InvalidMethodMessage}, none, _} ->
?LOG_WARN("Channel (~p): ignoring cast of ~p method. " ++
InvalidMethodMessage ++ "~n", [self(), Method]),
InvalidMethodMessage ++ "", [self(), Method]),
{noreply, State};
{{InvalidMethodReply, _}, _, _} ->
{reply, {error, InvalidMethodReply}, State}
Expand Down Expand Up @@ -695,7 +695,7 @@ safely_handle_method_from_server(Method, Content,
_ -> false
end,
if Drop -> ?LOG_INFO("Channel (~p): dropping method ~p from "
"server because channel is closing~n",
"server because channel is closing",
[self(), {Method, Content}]),
{noreply, State};
true ->
Expand Down Expand Up @@ -776,7 +776,7 @@ handle_method_from_server1(
State = #state{return_handler = ReturnHandler}) ->
case ReturnHandler of
none -> ?LOG_WARN("Channel (~p): received {~p, ~p} but there is "
"no return handler registered~n",
"no return handler registered",
[self(), BasicReturn, AmqpMsg]);
{Pid, _Ref} -> Pid ! {BasicReturn, AmqpMsg}
end,
Expand All @@ -791,7 +791,7 @@ handle_method_from_server1(#'basic.ack'{} = BasicAck, none,
handle_method_from_server1(#'basic.nack'{} = BasicNack, none,
#state{confirm_handler = none} = State) ->
?LOG_WARN("Channel (~p): received ~p but there is no "
"confirm handler registered~n", [self(), BasicNack]),
"confirm handler registered", [self(), BasicNack]),
{noreply, update_confirm_set(BasicNack, State)};
handle_method_from_server1(#'basic.nack'{} = BasicNack, none,
#state{confirm_handler = {CH, _Ref}} = State) ->
Expand Down Expand Up @@ -835,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 ~p, channel ~p - error:~n~p~n",
?LOG_ERR("connection ~p, channel ~p - error:~n~p",
[Connection, Number, Reason]),
{true, Code, _} = ?PROTOCOL:lookup_amqp_exception(ErrorName),
ReportedReason = {server_initiated_close, Code, Expl},
Expand Down Expand Up @@ -928,7 +928,7 @@ server_misbehaved(#amqp_error{} = AmqpError, State = #state{number = Number}) ->
handle_shutdown({server_misbehaved, AmqpError}, State);
{_, Close} ->
?LOG_WARN("Channel (~p) flushing and closing due to soft "
"error caused by the server ~p~n", [self(), AmqpError]),
"error caused by the server ~p", [self(), AmqpError]),
Self = self(),
spawn(fun () -> call(Self, Close) end),
{noreply, State}
Expand Down
2 changes: 1 addition & 1 deletion deps/amqp_client/src/amqp_channels_manager.erl
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ internal_pass_frame(Number, Frame, State) ->
case internal_lookup_npa(Number, State) of
undefined ->
?LOG_INFO("Dropping frame ~p for invalid or closed "
"channel number ~p~n", [Frame, Number]),
"channel number ~p", [Frame, Number]),
State;
{ChPid, AState} ->
NewAState = process_channel_frame(Frame, Number, ChPid, AState),
Expand Down
10 changes: 5 additions & 5 deletions deps/amqp_client/src/amqp_gen_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ 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 (~p) closing: internal error in channel (~p): ~p~n",
?LOG_WARN("Connection (~p) closing: internal error in channel (~p): ~p",
[self(), Pid, Reason]),
internal_error(Pid, Reason, State);
handle_cast({server_misbehaved, AmqpError}, State) ->
Expand All @@ -218,12 +218,12 @@ handle_cast({register_blocked_handler, HandlerPid}, State) ->
handle_info({'DOWN', _, process, BlockHandler, Reason},
State = #state{block_handler = {BlockHandler, _Ref}}) ->
?LOG_WARN("Connection (~p): Unregistering connection.{blocked,unblocked} handler ~p because it died. "
"Reason: ~p~n", [self(), BlockHandler, Reason]),
"Reason: ~p", [self(), BlockHandler, Reason]),
{noreply, State#state{block_handler = none}};
handle_info({'EXIT', BlockHandler, Reason},
State = #state{block_handler = {BlockHandler, Ref}}) ->
?LOG_WARN("Connection (~p): Unregistering connection.{blocked,unblocked} handler ~p because it died. "
"Reason: ~p~n", [self(), BlockHandler, Reason]),
"Reason: ~p", [self(), BlockHandler, Reason]),
erlang:demonitor(Ref, [flush]),
{noreply, State#state{block_handler = none}};
%% propagate the exit to the module that will stop with a sensible reason logged
Expand Down Expand Up @@ -329,12 +329,12 @@ internal_error(Pid, Reason, State) ->

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

server_misbehaved_close(AmqpError, State) ->
?LOG_WARN("Connection (~p) closing: server misbehaved: ~p~n",
?LOG_WARN("Connection (~p) closing: server misbehaved: ~p",
[self(), AmqpError]),
{0, Close} = rabbit_binary_generator:map_exception(0, AmqpError, ?PROTOCOL),
set_closing_state(abrupt, #closing{reason = server_misbehaved,
Expand Down
4 changes: 2 additions & 2 deletions deps/amqp_client/src/amqp_ssl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ maybe_add_verify(Options) ->
% NB: user has explicitly set 'verify'
Options;
_ ->
?LOG_WARN("Connection (~p): Certificate chain verification is not enabled for this TLS connection. "
"Please see https://rabbitmq.com/ssl.html for more information.~n", [self()]),
?LOG_WARN("Connection (~p): 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
8 changes: 4 additions & 4 deletions deps/rabbit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ endef
APPS_DIR := $(CURDIR)/apps

LOCAL_DEPS = sasl rabbitmq_prelaunch os_mon inets compiler public_key crypto ssl syntax_tools xmerl
BUILD_DEPS = rabbitmq_cli syslog
DEPS = cuttlefish ranch lager rabbit_common ra sysmon_handler stdout_formatter recon observer_cli osiris amqp10_common
BUILD_DEPS = rabbitmq_cli
DEPS = cuttlefish ranch rabbit_common ra sysmon_handler stdout_formatter recon observer_cli osiris amqp10_common syslog
TEST_DEPS = rabbitmq_ct_helpers rabbitmq_ct_client_helpers amqp_client meck proper

PLT_APPS += mnesia

dep_cuttlefish = hex 2.7.0
dep_syslog = git https://github.com/schlagert/syslog 3.4.5
dep_cuttlefish = git https://github.com/Kyorai/cuttlefish master
dep_syslog = git https://github.com/schlagert/syslog 4.0.0
dep_osiris = git https://github.com/rabbitmq/osiris master

define usage_xml_to_erl
Expand Down
1 change: 1 addition & 0 deletions deps/rabbit/apps/rabbitmq_prelaunch/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.coverdata
/ebin/
/.erlang.mk/
/logs/
/rabbitmq_prelaunch.d
/xrefr

Expand Down
2 changes: 1 addition & 1 deletion deps/rabbit/apps/rabbitmq_prelaunch/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PROJECT_DESCRIPTION = RabbitMQ prelaunch setup
PROJECT_VERSION = 1.0.0
PROJECT_MOD = rabbit_prelaunch_app

DEPS = rabbit_common lager
DEPS = rabbit_common jsx

DEP_PLUGINS = rabbit_common/mk/rabbitmq-build.mk

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

-module(rabbit_boot_state).

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

-include_lib("rabbit_common/include/logging.hrl").

-export([get/0,
set/1,
wait_for/2,
Expand All @@ -28,7 +31,8 @@ get() ->

-spec set(boot_state()) -> ok.
set(BootState) ->
rabbit_log_prelaunch:debug("Change boot state to `~s`", [BootState]),
?LOG_DEBUG("Change boot state to `~s`", [BootState],
#{domain => ?RMQLOG_DOMAIN_PRELAUNCH}),
?assert(is_valid(BootState)),
case BootState of
stopped -> persistent_term:erase(?PT_KEY_BOOT_STATE);
Expand Down
Loading