Sfoglia il codice sorgente

Make the size of messages in the crash log configurable

pull/4/head
Andrew Thompson 14 anni fa
parent
commit
dae643f8dd
3 ha cambiato i file con 16 aggiunte e 11 eliminazioni
  1. +2
    -0
      src/lager.app.src
  2. +9
    -10
      src/lager_crash_log.erl
  3. +5
    -1
      src/lager_sup.erl

+ 2
- 0
src/lager.app.src Vedi File

@ -18,6 +18,8 @@
{"log/console.log", info}]}]},
%% Whether to write a crash log, and where. Undefined means no crash logger.
{crash_log, "log/crash.log"},
%% Maximum size in bytes of events in the crash log - defaults to 4096
{crash_log_size, 4096},
%% Whether to redirect error_logger messages into lager - defaults to true
{error_logger_redirect, true}
]}

+ 9
- 10
src/lager_crash_log.erl Vedi File

@ -30,28 +30,29 @@
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
code_change/3]).
-export([start_link/1, start/1]).
-export([start_link/2, start/2]).
-record(state, {
name,
fd,
inode,
fmtmaxbytes,
flap=false
}).
%% @private
start_link(Filename) ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [Filename], []).
start_link(Filename, MaxBytes) ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [Filename, MaxBytes], []).
%% @private
start(Filename) ->
gen_server:start({local, ?MODULE}, ?MODULE, [Filename], []).
start(Filename, MaxBytes) ->
gen_server:start({local, ?MODULE}, ?MODULE, [Filename, MaxBytes], []).
%% @private
init([Filename]) ->
init([Filename, MaxBytes]) ->
case lager_util:open_logfile(Filename, false) of
{ok, {FD, Inode}} ->
{ok, #state{name=Filename, fd=FD, inode=Inode}};
{ok, #state{name=Filename, fd=FD, inode=Inode, fmtmaxbytes=MaxBytes}};
Error ->
Error
end.
@ -61,9 +62,7 @@ handle_call(_Call, _From, State) ->
{reply, ok, State}.
%% @private
handle_cast({log, Event}, #state{name=Name, fd=FD, inode=Inode, flap=Flap} = State) ->
%% TODO these should probably be configurable and have saner defaults
FmtMaxBytes = 1024,
handle_cast({log, Event}, #state{name=Name, fd=FD, inode=Inode, flap=Flap, fmtmaxbytes=FmtMaxBytes} = State) ->
TermMaxSize = 500,
%% borrowed from riak_err
{ReportStr, Pid, MsgStr, _ErrorP} = case Event of

+ 5
- 1
src/lager_sup.erl Vedi File

@ -41,7 +41,11 @@ init([]) ->
%% check if the crash log is enabled
Crash = case application:get_env(lager, crash_log) of
{ok, File} ->
[{lager_crash_log, {lager_crash_log, start_link, [File]},
MaxBytes = case application:get_env(lager, crash_log_size) of
{ok, Val} -> Val;
_ -> 4096
end,
[{lager_crash_log, {lager_crash_log, start_link, [File, MaxBytes]},
permanent, 5000, worker, [lager_crash_log]}];
_ ->
[]

Caricamento…
Annulla
Salva