Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 304 lines (277 sloc) 11.875 kB
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
1 %% Copyright (c) 2011 Basho Technologies, Inc. All Rights Reserved.
2 %%
3 %% This file is provided to you under the Apache License,
4 %% Version 2.0 (the "License"); you may not use this file
5 %% except in compliance with the License. You may obtain
6 %% a copy of the License at
7 %%
8 %% http://www.apache.org/licenses/LICENSE-2.0
9 %%
10 %% Unless required by applicable law or agreed to in writing,
11 %% software distributed under the License is distributed on an
12 %% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 %% KIND, either express or implied. See the License for the
14 %% specific language governing permissions and limitations
15 %% under the License.
16
862a9cb @Vagabond Documentation!
Vagabond authored
17 %% @doc A error_logger backend for redirecting events into lager.
18 %% Error messages and crash logs are also optionally written to a crash log.
19
20 %% @see lager_crash_log
21
22 %% @private
23
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
24 -module(error_logger_lager_h).
25
886d410 @Vagabond Make highest log level be 0; add some helper macros
Vagabond authored
26 -include("lager.hrl").
27
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
28 -behaviour(gen_event).
29
30 -export([init/1, handle_call/2, handle_event/2, handle_info/2, terminate/2,
31 code_change/3]).
32
1f3493d @Vagabond Restart error_logger handler if it exits, cleanups
Vagabond authored
33 -export([format_reason/1]).
34
399e43f @Vagabond Check threshold when generating messages from error_logger
Vagabond authored
35 -define(LOG(Level, Pid, Msg),
886d410 @Vagabond Make highest log level be 0; add some helper macros
Vagabond authored
36 case ?SHOULD_LOG(Level) of
399e43f @Vagabond Check threshold when generating messages from error_logger
Vagabond authored
37 true ->
efc7b75 @Vagabond Changes suggested by Kostis, Dialyzer -Wunmatched_returns and Tidier
Vagabond authored
38 _ =lager:log(Level, Pid, Msg),
39 ok;
399e43f @Vagabond Check threshold when generating messages from error_logger
Vagabond authored
40 _ -> ok
41 end).
42
43 -define(LOG(Level, Pid, Fmt, Args),
886d410 @Vagabond Make highest log level be 0; add some helper macros
Vagabond authored
44 case ?SHOULD_LOG(Level) of
399e43f @Vagabond Check threshold when generating messages from error_logger
Vagabond authored
45 true ->
efc7b75 @Vagabond Changes suggested by Kostis, Dialyzer -Wunmatched_returns and Tidier
Vagabond authored
46 _ = lager:log(Level, Pid, Fmt, Args),
47 ok;
399e43f @Vagabond Check threshold when generating messages from error_logger
Vagabond authored
48 _ -> ok
49 end).
50
b61718f @Vagabond Make the call to the crash log synchronous only when testing
Vagabond authored
51 -ifdef(TEST).
52 %% Make CRASH synchronous when testing, to avoid timing headaches
fed1103 @Vagabond Add a crash.log logger, based on riak_err, that logs error reports in…
Vagabond authored
53 -define(CRASH_LOG(Event),
4dfee06 @Vagabond Make tests less dependant on timer:sleeps to function correctly
Vagabond authored
54 catch(gen_server:call(lager_crash_log, {log, Event}))).
b61718f @Vagabond Make the call to the crash log synchronous only when testing
Vagabond authored
55 -else.
56 -define(CRASH_LOG(Event),
57 gen_server:cast(lager_crash_log, {log, Event})).
58 -endif.
fed1103 @Vagabond Add a crash.log logger, based on riak_err, that logs error reports in…
Vagabond authored
59
ec61e88 @Vagabond Make the dialyzer happy.
Vagabond authored
60 -spec init(any()) -> {ok, {}}.
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
61 init(_) ->
62 {ok, {}}.
63
64 handle_call(_Request, State) ->
65 {ok, ok, State}.
66
67 handle_event(Event, State) ->
68 case Event of
69 {error, _GL, {Pid, Fmt, Args}} ->
b7a5648 @Vagabond A bunch more work on the error_logger interop
Vagabond authored
70 case Fmt of
71 "** Generic server "++_ ->
72 %% gen_server terminate
73 [Name, _Msg, _State, Reason] = Args,
fed1103 @Vagabond Add a crash.log logger, based on riak_err, that logs error reports in…
Vagabond authored
74 ?CRASH_LOG(Event),
399e43f @Vagabond Check threshold when generating messages from error_logger
Vagabond authored
75 ?LOG(error, Pid, "gen_server ~w terminated with reason: ~s",
b7a5648 @Vagabond A bunch more work on the error_logger interop
Vagabond authored
76 [Name, format_reason(Reason)]);
77 "** State machine "++_ ->
78 %% gen_fsm terminate
79 [Name, _Msg, StateName, _StateData, Reason] = Args,
fed1103 @Vagabond Add a crash.log logger, based on riak_err, that logs error reports in…
Vagabond authored
80 ?CRASH_LOG(Event),
399e43f @Vagabond Check threshold when generating messages from error_logger
Vagabond authored
81 ?LOG(error, Pid, "gen_fsm ~w in state ~w terminated with reason: ~s",
b7a5648 @Vagabond A bunch more work on the error_logger interop
Vagabond authored
82 [Name, StateName, format_reason(Reason)]);
83 "** gen_event handler"++_ ->
84 %% gen_event handler terminate
85 [ID, Name, _Msg, _State, Reason] = Args,
fed1103 @Vagabond Add a crash.log logger, based on riak_err, that logs error reports in…
Vagabond authored
86 ?CRASH_LOG(Event),
399e43f @Vagabond Check threshold when generating messages from error_logger
Vagabond authored
87 ?LOG(error, Pid, "gen_event ~w installed in ~w terminated with reason: ~s",
b7a5648 @Vagabond A bunch more work on the error_logger interop
Vagabond authored
88 [ID, Name, format_reason(Reason)]);
89 _ ->
fed1103 @Vagabond Add a crash.log logger, based on riak_err, that logs error reports in…
Vagabond authored
90 ?CRASH_LOG(Event),
83c2a41 @slfritchie Mash in the remainder of adt-error-format-protection branch
slfritchie authored
91 ?LOG(error, Pid, lager:safe_format(Fmt, Args, 4096))
b7a5648 @Vagabond A bunch more work on the error_logger interop
Vagabond authored
92 end;
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
93 {error_report, _GL, {Pid, std_error, D}} ->
fed1103 @Vagabond Add a crash.log logger, based on riak_err, that logs error reports in…
Vagabond authored
94 ?CRASH_LOG(Event),
399e43f @Vagabond Check threshold when generating messages from error_logger
Vagabond authored
95 ?LOG(error, Pid, print_silly_list(D));
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
96 {error_report, _GL, {Pid, supervisor_report, D}} ->
fed1103 @Vagabond Add a crash.log logger, based on riak_err, that logs error reports in…
Vagabond authored
97 ?CRASH_LOG(Event),
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
98 case lists:sort(D) of
99 [{errorContext, Ctx}, {offender, Off}, {reason, Reason}, {supervisor, Name}] ->
100 Offender = format_offender(Off),
052b639 @Vagabond Wrap to 80 columns
Vagabond authored
101 ?LOG(error, Pid,
102 "Supervisor ~w had child ~s exit with reason ~s in context ~w",
103 [element(2, Name), Offender, format_reason(Reason), Ctx]);
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
104 _ ->
10153cf @Vagabond Optimize list construction, somewhat
Vagabond authored
105 ?LOG(error, Pid, ["SUPERVISOR REPORT ", print_silly_list(D)])
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
106 end;
b7a5648 @Vagabond A bunch more work on the error_logger interop
Vagabond authored
107 {error_report, _GL, {Pid, crash_report, [Self, Neighbours]}} ->
fed1103 @Vagabond Add a crash.log logger, based on riak_err, that logs error reports in…
Vagabond authored
108 ?CRASH_LOG(Event),
10153cf @Vagabond Optimize list construction, somewhat
Vagabond authored
109 ?LOG(error, Pid, ["CRASH REPORT ", format_crash_report(Self, Neighbours)]);
5b9a4c6 @Vagabond Support warning messages, put commas between terms in report messages
Vagabond authored
110 {warning_msg, _GL, {Pid, Fmt, Args}} ->
83c2a41 @slfritchie Mash in the remainder of adt-error-format-protection branch
slfritchie authored
111 ?LOG(warning, Pid, lager:safe_format(Fmt, Args, 4096));
5b9a4c6 @Vagabond Support warning messages, put commas between terms in report messages
Vagabond authored
112 {warning_report, _GL, {Pid, std_warning, Report}} ->
113 ?LOG(warning, Pid, print_silly_list(Report));
b7a5648 @Vagabond A bunch more work on the error_logger interop
Vagabond authored
114 {info_msg, _GL, {Pid, Fmt, Args}} ->
83c2a41 @slfritchie Mash in the remainder of adt-error-format-protection branch
slfritchie authored
115 ?LOG(info, Pid, lager:safe_format(Fmt, Args, 4096));
e9abf79 @Vagabond Handle 'single term' error_logger reports
Vagabond authored
116 {info_report, _GL, {Pid, std_info, D}} when is_list(D) ->
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
117 Details = lists:sort(D),
118 case Details of
119 [{application, App}, {exited, Reason}, {type, _Type}] ->
53d5de4 @Vagabond Fix term printing in errors to properly show embedded lists
Vagabond authored
120 ?LOG(info, Pid, "Application ~w exited with reason: ~s",
121 [App, format_reason(Reason)]);
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
122 _ ->
399e43f @Vagabond Check threshold when generating messages from error_logger
Vagabond authored
123 ?LOG(info, Pid, print_silly_list(D))
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
124 end;
e9abf79 @Vagabond Handle 'single term' error_logger reports
Vagabond authored
125 {info_report, _GL, {Pid, std_info, D}} ->
126 ?LOG(info, Pid, "~w", [D]);
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
127 {info_report, _GL, {P, progress, D}} ->
128 Details = lists:sort(D),
129 case Details of
130 [{application, App}, {started_at, Node}] ->
399e43f @Vagabond Check threshold when generating messages from error_logger
Vagabond authored
131 ?LOG(info, P, "Application ~w started on node ~w",
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
132 [App, Node]);
133 [{started, Started}, {supervisor, Name}] ->
134 MFA = format_mfa(proplists:get_value(mfargs, Started)),
135 Pid = proplists:get_value(pid, Started),
052b639 @Vagabond Wrap to 80 columns
Vagabond authored
136 ?LOG(debug, P, "Supervisor ~w started ~s at pid ~w",
137 [element(2, Name), MFA, Pid]);
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
138 _ ->
10153cf @Vagabond Optimize list construction, somewhat
Vagabond authored
139 ?LOG(info, P, ["PROGRESS REPORT ", print_silly_list(D)])
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
140 end;
141 _ ->
af2f220 @Vagabond Log unexpected error_logger messages to lager
Vagabond authored
142 ?LOG(warning, self(), "Unexpected error_logger event ~w", [Event])
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
143 end,
144 {ok, State}.
145
146 handle_info(_Info, State) ->
147 {ok, State}.
148
149 terminate(_Reason, _State) ->
150 ok.
151
152 code_change(_OldVsn, State, _Extra) ->
153 {ok, State}.
154
155 %% internal functions
156
1f3493d @Vagabond Restart error_logger handler if it exits, cleanups
Vagabond authored
157 format_crash_report(Report, Neighbours) ->
de5d84e @Vagabond Fix how the name/pid of the process is printed in crash reports
Vagabond authored
158 Name = case proplists:get_value(registered_name, Report, []) of
159 [] ->
160 %% process_info(Pid, registered_name) returns [] for unregistered processes
161 proplists:get_value(pid, Report);
162 Atom -> Atom
163 end,
c21f1bd @Vagabond Better crash reports for processes started via proc_lib, Fixes #31
Vagabond authored
164 {_Class, Reason, Trace} = proplists:get_value(error_info, Report),
165 ReasonStr = case is_atom(Reason) of
166 true ->
167 format_reason({Reason, Trace});
168 _ ->
169 format_reason(Reason)
170 end,
052b639 @Vagabond Wrap to 80 columns
Vagabond authored
171 io_lib:format("Process ~w with ~w neighbours crashed with reason: ~s",
c21f1bd @Vagabond Better crash reports for processes started via proc_lib, Fixes #31
Vagabond authored
172 [Name, length(Neighbours), ReasonStr]).
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
173
174 format_offender(Off) ->
6fdbe25 @Vagabond Use mfargs instead of name attribute as the way to detect supervisor_…
Vagabond authored
175 case proplists:get_value(mfargs, Off) of
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
176 undefined ->
177 %% supervisor_bridge
052b639 @Vagabond Wrap to 80 columns
Vagabond authored
178 io_lib:format("at module ~w at ~w",
179 [proplists:get_value(mod, Off), proplists:get_value(pid, Off)]);
6fdbe25 @Vagabond Use mfargs instead of name attribute as the way to detect supervisor_…
Vagabond authored
180 MFArgs ->
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
181 %% regular supervisor
6fdbe25 @Vagabond Use mfargs instead of name attribute as the way to detect supervisor_…
Vagabond authored
182 MFA = format_mfa(MFArgs),
183 Name = proplists:get_value(name, Off),
dc750f5 @Vagabond Supervisor children are not guranteed to be atoms. Fixes issue #33
Vagabond authored
184 io_lib:format("~p started with ~s at ~w",
052b639 @Vagabond Wrap to 80 columns
Vagabond authored
185 [Name, MFA, proplists:get_value(pid, Off)])
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
186 end.
187
7696cc9 @Vagabond More tests
Vagabond authored
188 format_reason({'function not exported', [{M, F, A},MFA|_]}) ->
052b639 @Vagabond Wrap to 80 columns
Vagabond authored
189 ["call to undefined function ", format_mfa({M, F, length(A)}),
190 " from ", format_mfa(MFA)];
807a847 @Vagabond Fix tests. and 2 places MFAs werent handling the new 4th parameter
Vagabond authored
191 format_reason({'function not exported', [{M, F, A, _Props},MFA|_]}) ->
192 %% R15 line numbers
193 ["call to undefined function ", format_mfa({M, F, length(A)}),
194 " from ", format_mfa(MFA)];
900aaca @Vagabond Formatters for a bunch more common exceptions
Vagabond authored
195 format_reason({undef, [MFA|_]}) ->
10153cf @Vagabond Optimize list construction, somewhat
Vagabond authored
196 ["call to undefined function ", format_mfa(MFA)];
d68f4d8 @Vagabond Add support for bad_return errors from application start
Vagabond authored
197 format_reason({bad_return, {_MFA, {'EXIT', Reason}}}) ->
198 format_reason(Reason);
199 format_reason({bad_return, {MFA, Val}}) ->
200 ["bad return value ", print_val(Val), " from ", format_mfa(MFA)];
b7a5648 @Vagabond A bunch more work on the error_logger interop
Vagabond authored
201 format_reason({bad_return_value, Val}) ->
53d5de4 @Vagabond Fix term printing in errors to properly show embedded lists
Vagabond authored
202 ["bad return value: ", print_val(Val)];
203 format_reason({{bad_return_value, Val}, MFA}) ->
204 ["bad return value: ", print_val(Val), " in ", format_mfa(MFA)];
62bb41f @Vagabond Add support for badrecord errors
Vagabond authored
205 format_reason({{badrecord, Record}, [MFA|_]}) ->
206 ["bad record ", print_val(Record), " in ", format_mfa(MFA)];
900aaca @Vagabond Formatters for a bunch more common exceptions
Vagabond authored
207 format_reason({{case_clause, Val}, [MFA|_]}) ->
53d5de4 @Vagabond Fix term printing in errors to properly show embedded lists
Vagabond authored
208 ["no case clause matching ", print_val(Val), " in ", format_mfa(MFA)];
b7a5648 @Vagabond A bunch more work on the error_logger interop
Vagabond authored
209 format_reason({function_clause, [MFA|_]}) ->
10153cf @Vagabond Optimize list construction, somewhat
Vagabond authored
210 ["no function clause matching ", format_mfa(MFA)];
900aaca @Vagabond Formatters for a bunch more common exceptions
Vagabond authored
211 format_reason({if_clause, [MFA|_]}) ->
10153cf @Vagabond Optimize list construction, somewhat
Vagabond authored
212 ["no true branch found while evaluating if expression in ", format_mfa(MFA)];
900aaca @Vagabond Formatters for a bunch more common exceptions
Vagabond authored
213 format_reason({{try_clause, Val}, [MFA|_]}) ->
53d5de4 @Vagabond Fix term printing in errors to properly show embedded lists
Vagabond authored
214 ["no try clause matching ", print_val(Val), " in ", format_mfa(MFA)];
b7a5648 @Vagabond A bunch more work on the error_logger interop
Vagabond authored
215 format_reason({badarith, [MFA|_]}) ->
10153cf @Vagabond Optimize list construction, somewhat
Vagabond authored
216 ["bad arithmetic expression in ", format_mfa(MFA)];
b7a5648 @Vagabond A bunch more work on the error_logger interop
Vagabond authored
217 format_reason({{badmatch, Val}, [MFA|_]}) ->
53d5de4 @Vagabond Fix term printing in errors to properly show embedded lists
Vagabond authored
218 ["no match of right hand value ", print_val(Val), " in ", format_mfa(MFA)];
a6325a7 @Vagabond Add formatting for emfile and for various system limits
Vagabond authored
219 format_reason({emfile, _Trace}) ->
220 "maximum number of file descriptors exhausted, check ulimit -n";
221 format_reason({system_limit, [{M, F, _}|_] = Trace}) ->
222 Limit = case {M, F} of
223 {erlang, open_port} ->
224 "maximum number of ports exceeded";
225 {erlang, spawn} ->
226 "maximum number of processes exceeded";
227 {erlang, spawn_opt} ->
228 "maximum number of processes exceeded";
229 {erlang, list_to_atom} ->
230 "tried to create an atom larger than 255, or maximum atom count exceeded";
157d676 @Vagabond Handle ETS table count system limit
Vagabond authored
231 {ets, new} ->
232 "maximum number of ETS tables exceeded";
a6325a7 @Vagabond Add formatting for emfile and for various system limits
Vagabond authored
233 _ ->
4ac0137 @Vagabond Rename trunc_io to lager_trunc_io to prevent clashes
Vagabond authored
234 {Str, _} = lager_trunc_io:print(Trace, 500),
a6325a7 @Vagabond Add formatting for emfile and for various system limits
Vagabond authored
235 Str
236 end,
237 ["system limit: ", Limit];
7696cc9 @Vagabond More tests
Vagabond authored
238 format_reason({badarg, [MFA,MFA2|_]}) ->
900aaca @Vagabond Formatters for a bunch more common exceptions
Vagabond authored
239 case MFA of
807a847 @Vagabond Fix tests. and 2 places MFAs werent handling the new 4th parameter
Vagabond authored
240 {_M, _F, A, _Props} when is_list(A) ->
241 %% R15 line numbers
242 ["bad argument in call to ", format_mfa(MFA), " in ", format_mfa(MFA2)];
7696cc9 @Vagabond More tests
Vagabond authored
243 {_M, _F, A} when is_list(A) ->
10153cf @Vagabond Optimize list construction, somewhat
Vagabond authored
244 ["bad argument in call to ", format_mfa(MFA), " in ", format_mfa(MFA2)];
900aaca @Vagabond Formatters for a bunch more common exceptions
Vagabond authored
245 _ ->
246 %% seems to be generated by a bad call to a BIF
10153cf @Vagabond Optimize list construction, somewhat
Vagabond authored
247 ["bad argument in ", format_mfa(MFA)]
900aaca @Vagabond Formatters for a bunch more common exceptions
Vagabond authored
248 end;
249 format_reason({{badarity, {Fun, Args}}, [MFA|_]}) ->
250 {arity, Arity} = lists:keyfind(arity, 1, erlang:fun_info(Fun)),
052b639 @Vagabond Wrap to 80 columns
Vagabond authored
251 [io_lib:format("fun called with wrong arity of ~w instead of ~w in ",
252 [length(Args), Arity]), format_mfa(MFA)];
900aaca @Vagabond Formatters for a bunch more common exceptions
Vagabond authored
253 format_reason({noproc, MFA}) ->
10153cf @Vagabond Optimize list construction, somewhat
Vagabond authored
254 ["no such process or port in call to ", format_mfa(MFA)];
6916a66 @Vagabond Added badfun support, and tests for progress reports
Vagabond authored
255 format_reason({{badfun, Term}, [MFA|_]}) ->
53d5de4 @Vagabond Fix term printing in errors to properly show embedded lists
Vagabond authored
256 ["bad function ", print_val(Term), " in ", format_mfa(MFA)];
b7a5648 @Vagabond A bunch more work on the error_logger interop
Vagabond authored
257 format_reason(Reason) ->
4ac0137 @Vagabond Rename trunc_io to lager_trunc_io to prevent clashes
Vagabond authored
258 {Str, _} = lager_trunc_io:print(Reason, 500),
b7a5648 @Vagabond A bunch more work on the error_logger interop
Vagabond authored
259 Str.
260
261 format_mfa({M, F, A}) when is_list(A) ->
53d5de4 @Vagabond Fix term printing in errors to properly show embedded lists
Vagabond authored
262 {FmtStr, Args} = format_args(A, [], []),
263 io_lib:format("~w:~w("++FmtStr++")", [M, F | Args]);
b7a5648 @Vagabond A bunch more work on the error_logger interop
Vagabond authored
264 format_mfa({M, F, A}) when is_integer(A) ->
265 io_lib:format("~w:~w/~w", [M, F, A]);
68065c1 @Vagabond Intial support for R15 line numbers in errors
Vagabond authored
266 format_mfa({M, F, A, Props}) when is_list(Props) ->
b52e204 @Vagabond Don't bother printing the filename in error messages, it is always re…
Vagabond authored
267 case proplists:get_value(line, Props) of
268 undefined ->
68065c1 @Vagabond Intial support for R15 line numbers in errors
Vagabond authored
269 format_mfa({M, F, A});
b52e204 @Vagabond Don't bother printing the filename in error messages, it is always re…
Vagabond authored
270 Line ->
271 [format_mfa({M, F, A}), io_lib:format(" line ~w", [Line])]
68065c1 @Vagabond Intial support for R15 line numbers in errors
Vagabond authored
272 end;
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
273 format_mfa(Other) ->
b7a5648 @Vagabond A bunch more work on the error_logger interop
Vagabond authored
274 io_lib:format("~w", [Other]).
275
53d5de4 @Vagabond Fix term printing in errors to properly show embedded lists
Vagabond authored
276 format_args([], FmtAcc, ArgsAcc) ->
277 {string:join(lists:reverse(FmtAcc), ", "), lists:reverse(ArgsAcc)};
278 format_args([H|T], FmtAcc, ArgsAcc) ->
279 {Str, _} = lager_trunc_io:print(H, 100),
280 format_args(T, ["~s"|FmtAcc], [Str|ArgsAcc]).
7e68976 @Vagabond Try to improve M:F(A) printing a little
Vagabond authored
281
e9abf79 @Vagabond Handle 'single term' error_logger reports
Vagabond authored
282 print_silly_list(L) when is_list(L) ->
b7a5648 @Vagabond A bunch more work on the error_logger interop
Vagabond authored
283 case lager_stdlib:string_p(L) of
0d3e45a @Vagabond Plug some large error_logger message holes with trunc_io
Vagabond authored
284 true ->
285 lager_trunc_io:format("~s", [L], 4096);
286 _ ->
287 print_silly_list(L, [], [])
e9abf79 @Vagabond Handle 'single term' error_logger reports
Vagabond authored
288 end;
289 print_silly_list(L) ->
0d3e45a @Vagabond Plug some large error_logger message holes with trunc_io
Vagabond authored
290 {Str, _} = lager_trunc_io:print(L, 4096),
291 Str.
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
292
293 print_silly_list([], Fmt, Acc) ->
0d3e45a @Vagabond Plug some large error_logger message holes with trunc_io
Vagabond authored
294 lager_trunc_io:format(string:join(lists:reverse(Fmt), ", "),
295 lists:reverse(Acc), 4096);
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
296 print_silly_list([{K,V}|T], Fmt, Acc) ->
16fb558 @Vagabond Correct printing of strings in mixed error reports (reported by Bryan…
Vagabond authored
297 print_silly_list(T, ["~p: ~p" | Fmt], [V, K | Acc]);
04792f1 @Vagabond Initial version of error_logger->lager translator
Vagabond authored
298 print_silly_list([H|T], Fmt, Acc) ->
16fb558 @Vagabond Correct printing of strings in mixed error reports (reported by Bryan…
Vagabond authored
299 print_silly_list(T, ["~p" | Fmt], [H | Acc]).
53d5de4 @Vagabond Fix term printing in errors to properly show embedded lists
Vagabond authored
300
301 print_val(Val) ->
302 {Str, _} = lager_trunc_io:print(Val, 500),
303 Str.
Something went wrong with that request. Please try again.