From 2bf9be19efa4475e1d7541abddfb310477a19be9 Mon Sep 17 00:00:00 2001 From: SisMaker <1713699517@qq.com> Date: Sat, 6 Mar 2021 17:12:54 +0800 Subject: [PATCH] =?UTF-8?q?ft:=20rumCrashLog.erl=20=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/crashLog/rumCrashLog.erl | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/crashLog/rumCrashLog.erl b/src/crashLog/rumCrashLog.erl index c123244..8f44d59 100644 --- a/src/crashLog/rumCrashLog.erl +++ b/src/crashLog/rumCrashLog.erl @@ -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} =