#1 2025-09-06 03:59:09

zen010101
Member
Registered: 2024-06-15
Posts: 126

Log rotation is not working as expect

Offline

#2 2025-09-06 17:17:59

zen010101
Member
Registered: 2024-06-15
Posts: 126

Re: Log rotation is not working as expect

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

#3 2025-09-06 18:31:19

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,169
Website

Re: Log rotation is not working as expect

It sounded like a feature to me, since I expected to have a lot of Enter/Leave in the logs.

Of course, I understand it may not be the case.

Offline

#4 Today 07:36:44

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,169
Website

Re: Log rotation is not working as expect

Offline

Board footer

Powered by FluxBB