Skip to content

Commit 1aa2591

Browse files
author
Arnaud Bouchez
committed
core: fixed RotateFileSizeKB trigger if AutoFlushTimeOut is 0
1 parent 347367a commit 1aa2591

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/core/mormot.core.log.pas

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -954,12 +954,12 @@ TSynLogFamily = class
954954
read fWithInstancePointer write fWithInstancePointer;
955955
/// the time (in seconds) after which the log content must be written on
956956
// disk, whatever the current content size is
957-
// - by default, the log file will be written for every 8KB of log (see
958-
// BufferSize property) - this will ensure that the main application won't
959-
// be slow down by logging
960-
// - in order not to loose any log, a background thread can be created
961-
// and will be responsible of flushing all pending log content every
962-
// period of time (e.g. every 10 seconds)
957+
// - equals 0 by default, so that the log file will be written for every 8KB
958+
// of log (see BufferSize property) - to ensure that the main application
959+
// won't be slow down during logging
960+
// - in order not to loose any log, e.g. on an idle server, a background
961+
// thread can be created and will be responsible of flushing all pending
962+
// log content every period of time (e.g. every 10 seconds)
963963
property AutoFlushTimeOut: cardinal
964964
read fAutoFlushTimeOut write fAutoFlushTimeOut;
965965
{$ifdef OSWINDOWS}
@@ -6142,10 +6142,10 @@ procedure TSynLog.CreateLogWriter;
61426142
fWriterEcho.EchoAdd(fFamily.EchoCustom);
61436143
if Assigned(fFamily.fEchoRemoteClient) then
61446144
fWriterEcho.EchoAdd(fFamily.fEchoRemoteEvent);
6145+
fWriter.OnFlushToStream := OnFlushToStream; // note: overwrites fWriterEcho
61456146
// enable background writing in its own TAutoFlushThread
61466147
if fFamily.AutoFlushTimeOut <> 0 then
61476148
begin
6148-
fWriter.OnFlushToStream := OnFlushToStream; // note: overwrites fWriterEcho
61496149
OnFlushToStream(nil, 0);
61506150
fFamily.EnsureAutoFlushThreadRunning;
61516151
end;
@@ -6154,6 +6154,7 @@ procedure TSynLog.CreateLogWriter;
61546154
procedure TSynLog.OnFlushToStream(Text: PUtf8Char; Len: PtrInt);
61556155
var
61566156
flushsec, tix32: cardinal;
6157+
flushbytes: PtrInt;
61576158
begin
61586159
// compute the next idle timestamp for the background TAutoFlushThread
61596160
tix32 := 0;
@@ -6165,8 +6166,10 @@ procedure TSynLog.OnFlushToStream(Text: PUtf8Char; Len: PtrInt);
61656166
end;
61666167
// check for any PerformRotation - delayed in TSynLog.LogEnterFmt
61676168
if not (pendingRotate in fPendingFlags) then
6168-
if (fFileRotationBytes > 0) and // reached size to rotate?
6169-
(fWriter.WrittenBytes + Len > fFileRotationBytes) then
6169+
begin
6170+
flushbytes := fFileRotationBytes;
6171+
if (flushbytes > 0) and // reached size to rotate?
6172+
(fWriter.WrittenBytes + Len > flushbytes) then
61706173
include(fPendingFlags, pendingRotate)
61716174
else
61726175
begin
@@ -6180,6 +6183,7 @@ procedure TSynLog.OnFlushToStream(Text: PUtf8Char; Len: PtrInt);
61806183
// PerformRotation will call ComputeFileName to recompute DailyTix32
61816184
end;
61826185
end;
6186+
end;
61836187
// chain to the fWriterEcho process (otherwise Text/Len buffer is lost)
61846188
fWriterEcho.FlushToStream(Text, Len);
61856189
end;

src/mormot.commit.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
'2.3.12525'
1+
'2.3.12526'

0 commit comments

Comments
 (0)