You are not logged in.
Pages: 1
Offline
Based on code tracing, an excessively small RotateFileSizeKB is not the key cause of the issue. The PerformRotation method is only invoked within the following method:
procedure TSynLog.LogEnterFmt(nfo: PSynLogThreadInfo; inst: TObject;
fmt: PUtf8Char; args: PVarRec; argscount: PtrInt);
However, the check and invocation of PerformRotation are missing in the method below:
procedure TSynLog.LogEnter(nfo: PSynLogThreadInfo; inst: TObject; txt: PUtf8Char
{$ifdef ISDELPHI} ; addr: PtrUInt {$endif});
This means that calls like `l := TSynLog.Enter;` cannot trigger the rotation check.
This is the first bug.
Even if we use TSynLog.LogEnterFmt (which can trigger the rotation check), the check relies on the following condition:
if pendingRotate in fPendingFlags then // from OnFlushToStream
PerformRotation;
And the OnFlushToStream event is only assigned to fWriter.OnFlushToStream if AutoFlushTimeOut is explicitly set to a non-zero value:
if fFamily.AutoFlushTimeOut <> 0 then
begin
fWriter.OnFlushToStream := OnFlushToStream; // note: overwrites fWriterEcho
OnFlushToStream(nil, 0);
fFamily.EnsureAutoFlushThreadRunning;
end;
In other words, if I do not explicitly set AutoFlushTimeOut, OnFlushToStream will never be triggered—and consequently, PerformRotation will not run either.
This is the second bug.
Thirdly, even if the above two bugs are fixed, the PerformRotation check is only invoked in methods related to TSynLog.Enter. Calls like TSynLog.DoLog or TSynLog.Add.Log will still not trigger rotation checks. This behavior may require further improvement, or at the very least, explicit documentation to clarify it.
Offline
Should be better with
https://github.com/synopse/mORMot2/commit/1aa25915d
and
https://github.com/synopse/mORMot2/commit/a35674615
and
https://github.com/synopse/mORMot2/commit/e327e4a75 to harden the rotation itself.
Offline
Awesome! Thank you so much for the quick and thorough fix ?
I’ve just reviewed the commits, and they seem to address the key issues I mentioned earlier. I’ll take some time to test these changes carefully when I get the chance, and see if the rotation mechanism now works as expected.
Really appreciate your effort and continuous improvements—mORMot is getting stronger and better!
Offline
It was clearly some premature optimization from my side, during the TSynLog refactoring some weeks ago.
With these commits, we should be more correct, and with no performance impact: checking the pendingRotate flag for each log entries (but sllLeave) is minimal to execute.
Thanks to you for your detailed review, debug, deep explanation and minimum example.
Offline
Pages: 1