Skip to content
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

Logging: change ?LOG macro to ?WF_LOG #142

Merged
merged 1 commit into from
Aug 24, 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
8 changes: 4 additions & 4 deletions doc/markdown/crash.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ finish(_Config, State) ->

first_request(Type, Error, Stacktrace, _Config, _State) ->
%% Print the error message to the Erlang console
?LOG("~p~n", [{error, Type, Error, Stacktrace}]),
?WF_LOG("~p~n", [{error, Type, Error, Stacktrace}]),

%% Set the response status code to 500 (internal server error)
wf:status_code(500),
Expand All @@ -109,7 +109,7 @@ first_request(Type, Error, Stacktrace, _Config, _State) ->

postback_request(Type, Error, Stacktrace, _Config, _State) ->
%% Print the error message to the Erlang console
?LOG("~p~n", [{error, Type, Error, Stacktrace}]),
?WF_LOG("~p~n", [{error, Type, Error, Stacktrace}]),

%% Set the status code to 500 (internal server error)
wf:status_code(500),
Expand Down Expand Up @@ -143,7 +143,7 @@ finish(_Config, State) ->

first_request(Type, Error, Stacktrace, _Config, _State) ->
%% Print the error message to the Erlang console
?LOG("~p~n", [{error, Type, Error, Stacktrace}]),
?WF_LOG("~p~n", [{error, Type, Error, Stacktrace}]),

%% Set the response status code to 500 (internal server error)
wf:status_code(500),
Expand All @@ -164,7 +164,7 @@ body(Stacktrace) ->

postback_request(Type, Error, Stacktrace, _Config, _State) ->
%% Print the error message to the Erlang console
?LOG("~p~n", [{error, Type, Error, Stacktrace}]),
?WF_LOG("~p~n", [{error, Type, Error, Stacktrace}]),

%% Note, we don't set the status code to 500. If we did, the browser will
%% simply discard any javascript. So we keep a 200 status code and print
Expand Down
11 changes: 11 additions & 0 deletions include/wf.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,20 @@
%%% LOGGING %%%
-ifndef(debug_print).
-define(debug_print, true).

-ifndef(LOGGER_HRL).
-define(PRINT(Var), error_logger:info_msg("DEBUG: ~p~n~p:~p~n~p~n ~p~n", [self(), ?MODULE, ?LINE, ??Var, Var])).
-define(LOG(Msg, Args), error_logger:info_msg(Msg, Args)).
-define(WF_LOG(Msg, Args), error_logger:info_msg(Msg, Args)).
-define(DEBUG, error_logger:info_msg("DEBUG: ~p:~p~n", [?MODULE, ?LINE])).

-else.
%% logger.hrl has been included - avoid redefining the OTP ?LOG macro
-define(WF_LOG(Msg, Args), ?LOG_INFO(Msg, Args)).
-define(PRINT(Var), ?LOG_INFO("DEBUG: ~p: ~p~n", [??Var, Var])).
-define(DEBUG, ?LOG_INFO("DEBUG: ~p:~p~n", [?MODULE, ?LINE])).
-endif.

-endif.

%%% GUARDS %%%
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/crash/debug_crash_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ finish(_Config, State) ->

first_request(Type, Error, Stacktrace, _Config, _State) ->
Uri = wf:header(host) ++ wf:uri(),
?LOG("~p~n", [{error, first_request, {url, Uri}, {Type, Error, Stacktrace}}]),
?WF_LOG("~p~n", [{error, first_request, {url, Uri}, {Type, Error, Stacktrace}}]),
wf:status_code(500),
%% We use raw HTML here instead of Nitrogen elements in case the error is
%% internal to nitrogen (like if the element rendering system is broken).
Expand All @@ -28,7 +28,7 @@ first_request(Type, Error, Stacktrace, _Config, _State) ->

postback_request(Type, Error, Stacktrace, _Config, _State) ->
Uri = wf:header(host) ++ wf:uri(),
?LOG("~p~n", [{error, postback_request, {url, Uri}, {Type, Error, Stacktrace}}]),
?WF_LOG("~p~n", [{error, postback_request, {url, Uri}, {Type, Error, Stacktrace}}]),
ErrorMsg = <<"&#9888; An error occured performing this action. See console for details. &#9888;">>,
CloseBtn = <<"<a style='float:right; color: #f00' href='javascript:' onclick='Nitrogen.$hide_notice_bar()'>[&times;]</a>">>,
wf:wire([<<"Nitrogen.$show_notice_bar('error', \"">>, ErrorMsg , CloseBtn, <<"\")">>]),
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/crash/default_crash_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ finish(_Config, State) ->
{ok, State}.

first_request(Type, Error, Stacktrace, _Config, _State) ->
?LOG("~p~n", [{error, Type, Error, Stacktrace}]),
?WF_LOG("~p~n", [{error, Type, Error, Stacktrace}]),
wf:status_code(500),
"Internal Server Error".

postback_request(Type, Error, Stacktrace, _Config, _State) ->
?LOG("~p~n", [{error, Type, Error, Stacktrace}]),
?WF_LOG("~p~n", [{error, Type, Error, Stacktrace}]),
wf:status_code(500),
wf:console_log("Postback Crashed. See console for details"),
ok.
4 changes: 2 additions & 2 deletions src/wf_core.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ run_crash(Bridge, Type, Error, Stacktrace) ->
exit:normal ->
exit(normal);
Type2:Error2 ->
?LOG("Crash Handler Crashed:~n~p~n~nOriginal Crash:~n~p~n", [
?WF_LOG("Crash Handler Crashed:~n~p~n~nOriginal Crash:~n~p~n", [
{Type2, Error2, erlang:get_stacktrace()},
{Type, Error, Stacktrace}]),
Bridge1 = sbw:set_status_code(500, Bridge),
Expand All @@ -66,7 +66,7 @@ run_websocket_crash(Type, Error, Stacktrace) ->
crash_handler:postback_request(Type, Error, Stacktrace),
run_websocket_comet()
catch Type2:Error2 ->
?LOG("~p~n", [{error_in_crash_handler, Type2, Error2, erlang:get_stacktrace()}]),
?WF_LOG("~p~n", [{error_in_crash_handler, Type2, Error2, erlang:get_stacktrace()}]),
"Nitrogen.$console_log('crash_handler crashed in websocket');"
end.

Expand Down