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