Skip to content

Commit

Permalink
Make the default truncation limit a macro
Browse files Browse the repository at this point in the history
  • Loading branch information
Vagabond committed Sep 25, 2012
1 parent 350ba40 commit 55283cc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions include/lager.hrl
Expand Up @@ -22,6 +22,7 @@
message
}).

-define(DEFAULT_TRUNCATION, 4096).

-define(LEVELS,
[debug, info, notice, warning, error, critical, alert, emergency, none]).
Expand Down
12 changes: 6 additions & 6 deletions src/error_logger_lager_h.erl
Expand Up @@ -88,7 +88,7 @@ handle_event(Event, State) ->
[ID, Name, format_reason(Reason)]);
_ ->
?CRASH_LOG(Event),
?LOG(error, Pid, lager:safe_format(Fmt, Args, 4096))
?LOG(error, Pid, lager:safe_format(Fmt, Args, ?DEFAULT_TRUNCATION))
end;
{error_report, _GL, {Pid, std_error, D}} ->
?CRASH_LOG(Event),
Expand All @@ -108,11 +108,11 @@ handle_event(Event, State) ->
?CRASH_LOG(Event),
?LOG(error, Pid, "CRASH REPORT " ++ format_crash_report(Self, Neighbours));
{warning_msg, _GL, {Pid, Fmt, Args}} ->
?LOG(warning, Pid, lager:safe_format(Fmt, Args, 4096));
?LOG(warning, Pid, lager:safe_format(Fmt, Args, ?DEFAULT_TRUNCATION));
{warning_report, _GL, {Pid, std_warning, Report}} ->
?LOG(warning, Pid, print_silly_list(Report));
{info_msg, _GL, {Pid, Fmt, Args}} ->
?LOG(info, Pid, lager:safe_format(Fmt, Args, 4096));
?LOG(info, Pid, lager:safe_format(Fmt, Args, ?DEFAULT_TRUNCATION));
{info_report, _GL, {Pid, std_info, D}} when is_list(D) ->
Details = lists:sort(D),
case Details of
Expand Down Expand Up @@ -292,17 +292,17 @@ format_args([H|T], FmtAcc, ArgsAcc) ->
print_silly_list(L) when is_list(L) ->
case lager_stdlib:string_p(L) of
true ->
lager_trunc_io:format("~s", [L], 4096);
lager_trunc_io:format("~s", [L], ?DEFAULT_TRUNCATION);
_ ->
print_silly_list(L, [], [])
end;
print_silly_list(L) ->
{Str, _} = lager_trunc_io:print(L, 4096),
{Str, _} = lager_trunc_io:print(L, ?DEFAULT_TRUNCATION),
Str.

print_silly_list([], Fmt, Acc) ->
lager_trunc_io:format(string:join(lists:reverse(Fmt), ", "),
lists:reverse(Acc), 4096);
lists:reverse(Acc), ?DEFAULT_TRUNCATION);
print_silly_list([{K,V}|T], Fmt, Acc) ->
print_silly_list(T, ["~p: ~p" | Fmt], [V, K | Acc]);
print_silly_list([H|T], Fmt, Acc) ->
Expand Down
10 changes: 5 additions & 5 deletions src/lager.erl
Expand Up @@ -87,16 +87,16 @@ dispatch_log(Severity, Metadata, Format, Args, Size) when is_atom(Severity)->
%% @doc Manually log a message into lager without using the parse transform.
-spec log(log_level(), pid() | [tuple(),...], list()) -> ok | {error, lager_not_running}.
log(Level, Pid, Message) when is_pid(Pid) ->
dispatch_log(Level, [{pid,Pid}], Message, [], 4096);
dispatch_log(Level, [{pid,Pid}], Message, [], ?DEFAULT_TRUNCATION);
log(Level, Metadata, Message) when is_list(Metadata) ->
dispatch_log(Level, Metadata, Message, [], 4096).
dispatch_log(Level, Metadata, Message, [], ?DEFAULT_TRUNCATION).

%% @doc Manually log a message into lager without using the parse transform.
-spec log(log_level(), pid() | [tuple(),...], string(), list()) -> ok | {error, lager_not_running}.
log(Level, Pid, Format, Args) when is_pid(Pid) ->
dispatch_log(Level, [{pid,Pid}], Format, Args, 4096);
dispatch_log(Level, [{pid,Pid}], Format, Args, ?DEFAULT_TRUNCATION);
log(Level, Metadata, Format, Args) when is_list(Metadata) ->
dispatch_log(Level, Metadata, Format, Args, 4096).
dispatch_log(Level, Metadata, Format, Args, ?DEFAULT_TRUNCATION).

trace_file(File, Filter) ->
trace_file(File, Filter, debug).
Expand Down Expand Up @@ -239,7 +239,7 @@ posix_error(Error) when is_atom(Error) ->
Message -> Message
end;
posix_error(Error) ->
safe_format_chop("~p", [Error], 4096).
safe_format_chop("~p", [Error], ?DEFAULT_TRUNCATION).

%% @private
get_loglevels() ->
Expand Down
2 changes: 1 addition & 1 deletion src/lager_transform.erl
Expand Up @@ -29,7 +29,7 @@

%% @private
parse_transform(AST, Options) ->
TruncSize = proplists:get_value(lager_truncation_size, Options, 4096),
TruncSize = proplists:get_value(lager_truncation_size, Options, ?DEFAULT_TRUNCATION),
put(truncation_size, TruncSize),
walk_ast([], AST).

Expand Down

0 comments on commit 55283cc

Please sign in to comment.