Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Skeleton for all types of normal & SASL logs now in place

  • Loading branch information...
commit bba35569099a58a0aa4be62a940f01d33df93210 1 parent a06fde8
@slfritchie slfritchie authored
Showing with 118 additions and 24 deletions.
  1. +113 −19 src/riak_err_handler.erl
  2. +5 −5 src/riak_err_monitor.erl
View
132 src/riak_err_handler.erl
@@ -100,32 +100,108 @@ code_change(_OldVsn, State, _Extra) ->
%%% Internal functions
%%%----------------------------------------------------------------------
-format_event(Event, #state{max_len = MaxLen}) ->
- ReportStr = case Event of
- {error, _GL, _} -> "ERROR REPORT";
- %% SLF: non-standard string below.
- {emulator, _, _} -> "ERROR REPORT (emulator)";
- {error_report, _, {_, std_error, _}} -> "ERROR REPORT";
- {info, _, _} -> "INFO REPORT";
- {info_report, _, {_, std_info, _}} -> "INFO REPORT";
- {info_msg, _, _} -> "INFO REPORT";
- {warning_report, _, {_, std_warning, _}}-> "WARNING REPORT";
- {warning_msg, _, _} -> "WARNING REPORT";
- %% This type is ignored, so whatever.
- _ -> "ODD REPORT"
- end,
- Time = write_time(maybe_utc(erlang:localtime()), ReportStr),
- {Str, _} = trunc_io:print(Event, MaxLen),
- io_lib:format("~s: ~s: event str ~s\n", [Time, ?MODULE, Str]).
+format_event(Event, S) ->
+ %% Case clauses appear the same order as error_logger_tty_h:write_event/1.
+ {ReportStr, Pid, MsgStr} =
+ case Event of
+ {_Type, GL, _Msg} when node(GL) /= node() ->
+ {ignore, ignore, ignore};
+ {error, _GL, {Pid1, Fmt, Args}} ->
+ {"ERROR REPORT", Pid1, limited_fmt(Fmt, Args, S)};
+ %% SLF: non-standard string below.
+ {emulator, _GL, Chars} ->
+ {"ERROR REPORT", emulator, Chars};
+ {info, _GL, {Pid1, Info, _}} ->
+ {"INFO REPORT", Pid1, limited_str(Info, S)};
+ {error_report, _GL, {Pid1, std_error, Rep}} ->
+ {"ERROR REPORT", Pid1, limited_str(Rep, S)};
+ {error_report, _GL, Other} ->
+ perhaps_a_sasl_report(error_report, Other, S);
+ {info_report, _GL, {Pid1, std_info, Rep}} ->
+ {"INFO REPORT", Pid1, limited_str(Rep, S)};
+ {info_report, _GL, Other} ->
+ perhaps_a_sasl_report(info_report, Other, S);
+ {info_msg, _GL, {Pid1, Fmt, Args}} ->
+ {"INFO REPORT", Pid1, limited_fmt(Fmt, Args, S)};
+ {warning_report, _GL, {Pid1, std_warning, Rep}} ->
+ {"WARNING REPORT", Pid1, limited_str(Rep, S)};
+ {warning_msg, _GL, {Pid1, Fmt, Args}} ->
+ {"WARNING REPORT", Pid1, limited_fmt(Fmt, Args, S)};
+ %% This type is allegedly ignored, so whatever.
+ _E ->
+ {"ODD REPORT", "blahblah", limited_fmt("odd ~p", [_E], S)}
+ end,
+ if ReportStr == ignore ->
+ ok;
+ true ->
+ Time = write_time(maybe_utc(erlang:localtime()), ReportStr),
+ NodeSuffix = other_node_suffix(Pid),
+ io_lib:format("~s~s~s", [Time, MsgStr, NodeSuffix])
+ end.
+
+limited_fmt(Fmt, Args, _S) ->
+ io_lib:format("FIXME: " ++ Fmt, Args).
+
+limited_str(Term, S) ->
+ {Str, _} = trunc_io:print(Term, S#state.max_len),
+ Str.
+
+other_node_suffix(Pid) when node(Pid) =/= node() ->
+ "** at node " ++ atom_to_list(node(Pid)) ++ " **\n";
+other_node_suffix(_) ->
+ "".
+
+perhaps_a_sasl_report(error_report, {Pid, Type, Report}, S) ->
+ case is_my_error_report(Type) of
+ true ->
+ {sasl_type_to_report_head(Type), Pid,
+ sasl_limited_str(Type, Report, S)};
+ false ->
+ {ignore, ignore, ignore}
+ end;
+perhaps_a_sasl_report(info_report, {Pid, Type, Report}, S) ->
+ case is_my_info_report(Type) of
+ true ->
+ {sasl_type_to_report_head(Type), Pid,
+ sasl_limited_str(Type, Report, S)};
+ false ->
+ {ignore, ignore, ignore}
+ end;
+perhaps_a_sasl_report(_, _, _) ->
+ {ignore, ignore, ignore}.
+
+sasl_type_to_report_head(supervisor_report) ->
+ "SUPERVISOR REPORT";
+sasl_type_to_report_head(crash_report) ->
+ "CRASH REPORT";
+sasl_type_to_report_head(progress) ->
+ "PROGRESS REPORT".
+
+sasl_limited_str(supervisor_report, Report, _S) ->
+ Name = sup_get(supervisor, Report),
+ Context = sup_get(errorContext, Report),
+ Reason = sup_get(reason, Report),
+ Offender = sup_get(offender, Report),
+ FmtString = " Supervisor: ~p~n Context: ~p~n Reason: "
+ "~80.18p~n Offender: ~80.18p~n~n",
+ FmtString = " Supervisor: ~p~n Context: ~p~n Reason: "
+ "~80.18p~n Offender: ~80.18p~n~n",
+ io_lib:format("FixMe: " ++ FmtString, [Name, Context, Reason, Offender]);
+sasl_limited_str(progress, Report, _S) ->
+ [io_lib:format("FixMe ~16w: ~p~n",[Tag,Data]) || {Tag, Data} <- Report];
+sasl_limited_str(crash_repofg, Report, _S) ->
+ ["FixMe2: ", proc_lib:format(Report)].
%% From OTP stdlib's error_logger_tty_h.erl ... the !@#$! functions
%% aren't exported.
write_time({utc,{{Y,Mo,D},{H,Mi,S}}},Type) ->
- io_lib:format("~n=~s==== ~p-~s-~p::~s:~s:~s UTC ===~n",
+ %% TODO PUT ME BACK: io_lib:format("~n=~s==== ~p-~s-~p::~s:~s:~s UTC ===~n",
+ io_lib:format("~n-~s-==- ~p-~s-~p::~s:~s:~s UTC -=-~n",
[Type,D,month(Mo),Y,t(H),t(Mi),t(S)]);
write_time({{Y,Mo,D},{H,Mi,S}},Type) ->
- io_lib:format("~n=~s==== ~p-~s-~p::~s:~s:~s ===~n",
+ %% TODO PUT ME BACK: io_lib:format("~n=~s==== ~p-~s-~p::~s:~s:~s ===~n",
+ io_lib:format("~n-~s-==- ~p-~s-~p::~s:~s:~s -=-~n",
[Type,D,month(Mo),Y,t(H),t(Mi),t(S)]).
maybe_utc(Time) ->
@@ -167,3 +243,21 @@ month(9) -> "Sep";
month(10) -> "Oct";
month(11) -> "Nov";
month(12) -> "Dec".
+
+%% From OTP sasl's sasl_report.erl ... the !@#$! functions
+%% aren't exported.
+
+is_my_error_report(supervisor_report) -> true;
+is_my_error_report(crash_report) -> true;
+is_my_error_report(_) -> false.
+
+is_my_info_report(progress) -> true;
+is_my_info_report(_) -> false.
+
+sup_get(Tag, Report) ->
+ case lists:keysearch(Tag, 1, Report) of
+ {value, {_, Value}} ->
+ Value;
+ _ ->
+ ""
+ end.
View
10 src/riak_err_monitor.erl
@@ -56,13 +56,13 @@ init([]) ->
%% Add our custom handler.
ok = gen_event:add_sup_handler(error_logger, riak_err_handler, []),
- %% Disable the kernel default logger.
- error_logger:tty(false),
- %% Disable the SASL default logger.
+ %% Disable the default error logger.
+ gen_event:delete_handler(error_logger, error_logger,
+ {stop_please, ?MODULE}),
+ %% Disable the SASL default loggers.
gen_event:delete_handler(error_logger, sasl_report_tty_h,
{stop_please, ?MODULE}),
- %% Same for the default error logger.
- gen_event:delete_handler(error_logger, error_logger,
+ gen_event:delete_handler(error_logger, sasl_report_file_h,
{stop_please, ?MODULE}),
{ok, #state{}}.
Please sign in to comment.
Something went wrong with that request. Please try again.