Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lager log line truncated

I'm working on modifying some ejabberd code, and I'm coming across an error printed via lager:

2014-04-25 18:29:39.380 [error] emulator Error in process <0.652.0> on node 'ejabberd@localhost' with exit value: {function_clause,[{lists,zip,[[transport,connection,pid,method,version,peer,host,host_info,port,path,path_info,qs,qs_vals,bindings,headers,p_headers,cookies,meta,body_state,multipart,buffer,resp_compress...

Unfortunately the line is truncated and I can't see the rest of the stack trace. How do I view the whole error message?

like image 297
kjw0188 Avatar asked Apr 26 '14 01:04

kjw0188


2 Answers

I think the lager's trunc size can be adjusted as follows: In the lager.erl source file

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

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

The ?DEFAULT_TRUNCATION is defined in the lager.hrl file.

-define(DEFAULT_TRUNCATION, 4096).
-define(DEFAULT_TRACER, lager_default_tracer).

I think you could increase the above default value and then compile the lager again for use.

But your log's not as long as 4096, and the log's not from lager,but from lager's redirect (error_logger). The following question may be related to your problem: Truncated error report in erlang

like image 182
Chen Yu Avatar answered Nov 02 '22 22:11

Chen Yu


There are two possibilities. The first is to add the following compilation option to the erlc options in rebar/erlang.mk:

+'{lager_truncation_size, 20480}'

This will set the maximum allowed size of the total log to 20kb for all modules that are compiled by erlc, probably all of them in the project if you are not handing crafting a make file. The is a reason for the truncate limit is to not overload the lager processes so doing this across the whole project could be dangerous.

Note that adding this on a per module basis using the -compile attribute does not work, see this issue.

The other way is to call lager:dispatch_log youself, and bypass the transform:

lager:dispatch_log(info, [{pid, self()}], "hello ~s|", [lists:duplicate(1000, "hello")], 20480).

Both methods require that you make modifications to the code or build process.

like image 33
Andy Till Avatar answered Nov 03 '22 00:11

Andy Till