|
@ -104,7 +104,7 @@ init(LogFileConfig) when is_list(LogFileConfig) -> |
|
|
State0 = #state{name = Name, level = Level, size = Size, date = Date, count = Count, rotator = Rotator, |
|
|
State0 = #state{name = Name, level = Level, size = Size, date = Date, count = Count, rotator = Rotator, |
|
|
shaper = Shaper, formatter = Formatter, formatter_config = FormatterConfig, |
|
|
shaper = Shaper, formatter = Formatter, formatter_config = FormatterConfig, |
|
|
sync_on = SyncOn, sync_interval = SyncInterval, sync_size = SyncSize, check_interval = CheckInterval}, |
|
|
sync_on = SyncOn, sync_interval = SyncInterval, sync_size = SyncSize, check_interval = CheckInterval}, |
|
|
State = case Rotator:create_logfile(Name, {SyncSize, SyncInterval}) of |
|
|
|
|
|
|
|
|
State = case Rotator:createLogfile(Name, {SyncSize, SyncInterval}) of |
|
|
{ok, {FD, Inode, Ctime, _Size}} -> |
|
|
{ok, {FD, Inode, Ctime, _Size}} -> |
|
|
State0#state{fd = FD, inode = Inode, ctime = Ctime}; |
|
|
State0#state{fd = FD, inode = Inode, ctime = Ctime}; |
|
|
{error, Reason} -> |
|
|
{error, Reason} -> |
|
@ -173,7 +173,7 @@ handle_event(_Event, State) -> |
|
|
%% @private |
|
|
%% @private |
|
|
handle_info({rotate, File}, #state{name = File, count = Count, date = Date, rotator = Rotator} = State0) -> |
|
|
handle_info({rotate, File}, #state{name = File, count = Count, date = Date, rotator = Rotator} = State0) -> |
|
|
State1 = close_file(State0), |
|
|
State1 = close_file(State0), |
|
|
_ = Rotator:rotate_logfile(File, Count), |
|
|
|
|
|
|
|
|
_ = Rotator:rotateLogfile(File, Count), |
|
|
schedule_rotation(File, Date), |
|
|
schedule_rotation(File, Date), |
|
|
{ok, State1}; |
|
|
{ok, State1}; |
|
|
handle_info({shaper_expired, Name}, #state{shaper = Shaper, name = Name, formatter = Formatter, formatter_config = FormatConfig} = State) -> |
|
|
handle_info({shaper_expired, Name}, #state{shaper = Shaper, name = Name, formatter = Formatter, formatter_config = FormatConfig} = State) -> |
|
@ -227,12 +227,12 @@ write(#state{name = Name, fd = FD, |
|
|
true -> |
|
|
true -> |
|
|
%% need to check for rotation |
|
|
%% need to check for rotation |
|
|
Buffer = {State0#state.sync_size, State0#state.sync_interval}, |
|
|
Buffer = {State0#state.sync_size, State0#state.sync_interval}, |
|
|
case Rotator:ensure_logfile(Name, FD, Inode, Ctime, Buffer) of |
|
|
|
|
|
|
|
|
case Rotator:ensureLogfile(Name, FD, Inode, Ctime, Buffer) of |
|
|
{ok, {_FD, _Inode, _Ctime, Size}} when RotSize > 0, Size > RotSize -> |
|
|
{ok, {_FD, _Inode, _Ctime, Size}} when RotSize > 0, Size > RotSize -> |
|
|
State1 = close_file(State0), |
|
|
State1 = close_file(State0), |
|
|
case Rotator:rotate_logfile(Name, Count) of |
|
|
|
|
|
|
|
|
case Rotator:rotateLogfile(Name, Count) of |
|
|
ok -> |
|
|
ok -> |
|
|
%% go around the loop again, we'll do another rotation check and hit the next clause of ensure_logfile |
|
|
|
|
|
|
|
|
%% go around the loop again, we'll do another rotation check and hit the next clause of ensureLogfile |
|
|
write(State1, Timestamp, Level, Msg); |
|
|
write(State1, Timestamp, Level, Msg); |
|
|
{error, Reason} -> |
|
|
{error, Reason} -> |
|
|
case Flap of |
|
|
case Flap of |
|
@ -271,7 +271,7 @@ write_should_check(#state{last_check = LastCheck0, check_interval = CheckInterva |
|
|
_ -> |
|
|
_ -> |
|
|
% We need to know if the file has changed "out from under lager" so we don't |
|
|
% We need to know if the file has changed "out from under lager" so we don't |
|
|
% write to an invalid FD |
|
|
% write to an invalid FD |
|
|
{Result, _FInfo} = rumUtil:has_file_changed(Name, Inode0, Ctime0), |
|
|
|
|
|
|
|
|
{Result, _FInfo} = rumUtil:isFileChanged(Name, Inode0, Ctime0), |
|
|
Result |
|
|
Result |
|
|
end. |
|
|
end. |
|
|
|
|
|
|
|
@ -501,7 +501,7 @@ rotation_test_() -> |
|
|
% while a process has an open file handle referencing it |
|
|
% while a process has an open file handle referencing it |
|
|
ok; |
|
|
ok; |
|
|
_ -> |
|
|
_ -> |
|
|
{ok, {FD, Inode, Ctime, _Size}} = Rotator:open_logfile(TestLog, {SyncSize, SyncInterval}), |
|
|
|
|
|
|
|
|
{ok, {FD, Inode, Ctime, _Size}} = Rotator:openLogfile(TestLog, {SyncSize, SyncInterval}), |
|
|
State0 = DefaultState#state{fd = FD, inode = Inode, ctime = Ctime}, |
|
|
State0 = DefaultState#state{fd = FD, inode = Inode, ctime = Ctime}, |
|
|
State1 = write(State0, os:timestamp(), ?DEBUG, "hello world"), |
|
|
State1 = write(State0, os:timestamp(), ?DEBUG, "hello world"), |
|
|
?assertMatch(#state{name = TestLog, level = ?DEBUG, fd = FD, inode = Inode, ctime = Ctime}, State1), |
|
|
?assertMatch(#state{name = TestLog, level = ?DEBUG, fd = FD, inode = Inode, ctime = Ctime}, State1), |
|
@ -528,7 +528,7 @@ rotation_test_() -> |
|
|
RotationSize = 15, |
|
|
RotationSize = 15, |
|
|
PreviousCheck = os:timestamp(), |
|
|
PreviousCheck = os:timestamp(), |
|
|
|
|
|
|
|
|
{ok, {FD, Inode, Ctime, _Size}} = Rotator:open_logfile(TestLog, {SyncSize, SyncInterval}), |
|
|
|
|
|
|
|
|
{ok, {FD, Inode, Ctime, _Size}} = Rotator:openLogfile(TestLog, {SyncSize, SyncInterval}), |
|
|
State0 = DefaultState#state{ |
|
|
State0 = DefaultState#state{ |
|
|
fd = FD, inode = Inode, ctime = Ctime, size = RotationSize, |
|
|
fd = FD, inode = Inode, ctime = Ctime, size = RotationSize, |
|
|
check_interval = CheckInterval, last_check = PreviousCheck}, |
|
|
check_interval = CheckInterval, last_check = PreviousCheck}, |
|
|