Skip to content

Commit

Permalink
Merge 4166d3f into fe97fc5
Browse files Browse the repository at this point in the history
  • Loading branch information
GalaxyGorilla committed Oct 6, 2015
2 parents fe97fc5 + 4166d3f commit f3532a0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions include/hello_log.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

-define(LOG_REQUEST_request_stop(CallbackModule, HandlerId, Request, Response, Reason, Time, LogId),
lager:info(lists:append(?REQ_TRACES(CallbackModule, HandlerId, Request, ok, Response, LogId), [{hello_error_reason, Reason}]),
"Hello handler with callback '~p' and service id '~p' answered synced request on method(s) '~p' and stopped in '~w' ms.",
[CallbackModule, HandlerId, hello_log:get_method(Request), Time])).
"~p ~p / ~p : answered synced request.",
[node(), hello_log:stringify(CallbackModule), hello_log:get_method(Request)])).

-define(LOG_REQUEST_request_no_reply(CallbackModule, HandlerId, Request, Time, LogId),
lager:debug(?REQ_TRACES(CallbackModule, HandlerId, Request, ok, LogId),
Expand Down
17 changes: 14 additions & 3 deletions src/hello_log.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ format([ Request = #request{} | Requests]) ->
"[ " ++ format(Request) ++ " ], " ++ format(Requests);
format(#request{id = ID, method = Method, args = Args}) ->
lists:append(["ID: ", stringify(ID), "; METHOD: ", stringify(Method),
"; ARGS: ", stringify(Args)]);
"; ARGS: ", prettify_json(Args)]);

%% -- response formatting; first for record responses, then for arbitrary data blobs
format([ Response = #response{} ]) ->
"[ " ++ format(Response) ++ " ]";
format([ Response = #response{} | Responses]) ->
"[ " ++ format(Response) ++ " ], " ++ format(Responses);
format(#response{id = ID, response = CallbackResponse}) ->
lists:append(["ID: ", stringify(ID), "; RESPONSE: ", stringify(CallbackResponse)]);
lists:append(["ID: ", stringify(ID), "; RESPONSE: ", prettify_json(CallbackResponse)]);
format(ignore) -> ["ignored"];
format({ok, CallbackResponse}) -> stringify(CallbackResponse);
format(Msg) -> stringify(Msg).
Expand All @@ -64,5 +64,16 @@ get_method([ #request{method = Method} | Requests]) ->
get_method(#request{method = Method}) ->
stringify(Method).

stringify(Term) ->
stringify(Term) when is_binary(Term) ->
stringify(binary_to_list(Term));
stringify(Term) ->
lists:flatten(io_lib:format("~p", [Term])).

prettify_json(Term) ->
try
PrettyJson = jsx:format(jsx:encode(Term), [{space, 1}]),
binary_to_list(PrettyJson)
catch
_:_ ->
stringify(Term)
end.

0 comments on commit f3532a0

Please sign in to comment.