Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Commit

Permalink
Use user specified connection name in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Lebedeff committed Jun 1, 2016
1 parent 9010ea7 commit 4c7d882
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/rabbit_reader.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1134,21 +1134,22 @@ handle_method0(#'connection.start_ok'{mechanism = Mechanism,
response = Response,
client_properties = ClientProperties},
State0 = #v1{connection_state = starting,
connection = Connection,
connection = Connection0,
sock = Sock}) ->
AuthMechanism = auth_mechanism_to_module(Mechanism, Sock),
Capabilities =
case rabbit_misc:table_lookup(ClientProperties, <<"capabilities">>) of
{table, Capabilities1} -> Capabilities1;
_ -> []
end,
Connection1 = Connection0#connection{
client_properties = ClientProperties,
capabilities = Capabilities,
auth_mechanism = {Mechanism, AuthMechanism},
auth_state = AuthMechanism:init(Sock)},
Connection2 = augment_connection_name(Connection1),
State = State0#v1{connection_state = securing,
connection =
Connection#connection{
client_properties = ClientProperties,
capabilities = Capabilities,
auth_mechanism = {Mechanism, AuthMechanism},
auth_state = AuthMechanism:init(Sock)}},
connection = Connection2},
auth_phase(Response, State);

handle_method0(#'connection.secure_ok'{response = Response},
Expand Down Expand Up @@ -1505,3 +1506,20 @@ send_error_on_channel0_and_close(Channel, Protocol, Reason, State) ->
State1 = close_connection(terminate_channels(State)),
ok = send_on_channel0(State#v1.sock, CloseMethod, Protocol),
State1.

augment_connection_name(#connection{client_properties = ClientProperties,
name = Name0} = Connection) ->
UserSpecifiedName = rabbit_misc:table_lookup(ClientProperties, <<"connection_name">>),
Name = add_user_specified_name(Name0, UserSpecifiedName),
case Name of
Name0 -> % not chnaged
Connection;
_ ->
log(info, "Setting custom name on AMQP connection ~p (~s)~n", [self(), Name]),
Connection#connection{name = Name}
end.

add_user_specified_name(Name, {longstr, UserSpecifiedName}) ->
<<Name/binary, " - ", UserSpecifiedName/binary>>;
add_user_specified_name(Name, _) ->
Name.

0 comments on commit 4c7d882

Please sign in to comment.