Browse Source

ft: rumCrashLog.erl 相关修改

master
SisMaker 4 years ago
parent
commit
2bf9be19ef
1 changed files with 9 additions and 7 deletions
  1. +9
    -7
      src/crashLog/rumCrashLog.erl

+ 9
- 7
src/crashLog/rumCrashLog.erl View File

@ -33,8 +33,8 @@
-record(state, {
name :: string(),
fd :: pid() | undefined,
fileName :: string(), %%
fd :: pid() | undefined, %%
inode :: integer() | undefined,
ctime :: file:date_time() | undefined,
fmtmaxbytes :: integer(),
@ -51,16 +51,18 @@ start(Filename, MaxBytes, Size, Date, Count, Rotator) ->
start_link(Filename, MaxBytes, Size, Date, Count, Rotator) ->
gen_srv:start_link({local, ?MODULE}, ?MODULE, {Filename, MaxBytes, Size, Date, Count, Rotator}, []).
% File, MsgMaxBytes, RotationSize, RotationDate, RotationCount, RotationMod
init({RelFilename, MaxBytes, Size, Date, Count, Rotator}) ->
Filename = rumUtil:expand_path(RelFilename),
case Rotator:open_logfile(Filename, false) of
case Rotator:openLogFile(Filename, false) of
{ok, {FD, Inode, Ctime, _Size}} ->
schedule_rotation(Date),
{ok, #state{name = Filename, fd = FD, inode = Inode, ctime = Ctime, fmtmaxbytes = MaxBytes, size = Size, count = Count, date = Date, rotator = Rotator}};
{ok, #state{fileName = Filename, fd = FD, inode = Inode, ctime = Ctime, fmtmaxbytes = MaxBytes, size = Size, count = Count, date = Date, rotator = Rotator}};
{error, Reason} ->
?INT_LOG(error, "Failed to open crash log file ~ts with error: ~s",
[Filename, file:format_error(Reason)]),
{ok, #state{name = Filename, fmtmaxbytes = MaxBytes, flap = true, size = Size, count = Count, date = Date, rotator = Rotator}}
{ok, #state{fileName = Filename, fmtmaxbytes = MaxBytes, flap = true, size = Size, count = Count, date = Date, rotator = Rotator}}
end.
handleCall({log, _} = Log, State, _From) ->
@ -77,7 +79,7 @@ handleCast(_Msg, _State) ->
?ERR("~p cast receive unexpect msg ~p ~n ", [?MODULE, _Msg]),
kpS.
handleInfo(rotate, #state{name = Name, count = Count, date = Date, rotator = Rotator}) ->
handleInfo(rotate, #state{fileName = Name, count = Count, date = Date, rotator = Rotator}) ->
_ = Rotator:rotate_logfile(Name, Count),
schedule_rotation(Date),
kpS;
@ -165,7 +167,7 @@ sasl_limited_str(progress, Report, FmtMaxBytes) ->
sasl_limited_str(crash_report, Report, FmtMaxBytes) ->
rumStdlib:proc_lib_format(Report, FmtMaxBytes).
do_log({log, Event}, #state{name = Name, fd = FD, inode = Inode, ctime = Ctime, flap = Flap,
do_log({log, Event}, #state{fileName = Name, fd = FD, inode = Inode, ctime = Ctime, flap = Flap,
fmtmaxbytes = FmtMaxBytes, size = RotSize, count = Count, rotator = Rotator} = State) ->
%% borrowed from riak_err
{ReportStr, Pid, MsgStr, _ErrorP} =

Loading…
Cancel
Save