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

Commit e4bf110

Browse files
Merge pull request #42 from rabbitmq/rabbitmq-management-760
Include user in access logs
2 parents bf542fe + 48e8d7b commit e4bf110

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/webmachine_log_handler.erl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ code_change(_OldVsn, State, _Extra) ->
8787
%% This is one such part. The code is however equivalent to Webmachine's.
8888

8989
format_req({Status0, Body, Req}) ->
90-
User = "-",
90+
User = user_from_req(Req),
9191
Time = webmachine_log:fmtnow(),
9292
Status = integer_to_list(Status0),
9393
Length1 = case Body of
@@ -113,3 +113,16 @@ fmt_alog(Time, Ip, User, Method, Path, Version,
113113
" ", atom_to_list(Version), [$",$\s],
114114
Status, [$\s], Length, [$\s,$"], Referrer,
115115
[$",$\s,$"], UserAgent, [$",$\n]].
116+
117+
user_from_req(Req) ->
118+
try cowboy_req:parse_header(<<"authorization">>, Req) of
119+
{basic, Username, _} ->
120+
Username;
121+
{bearer, _} ->
122+
rabbit_data_coercion:to_binary(
123+
application:get_env(rabbitmq_management, uaa_client_id, ""));
124+
_ ->
125+
"-"
126+
catch _:_ ->
127+
"-"
128+
end.

0 commit comments

Comments
 (0)