-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathLoggerPro.pas
More file actions
3638 lines (3137 loc) · 138 KB
/
Copy pathLoggerPro.pas
File metadata and controls
3638 lines (3137 loc) · 138 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// *************************************************************************** }
//
// LoggerPro
//
// Copyright (c) 2010-2026 Daniele Teti
//
// https://github.com/danieleteti/loggerpro
//
// ***************************************************************************
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ***************************************************************************
unit LoggerPro;
{$SCOPEDENUMS ON}
interface
uses
System.Generics.Collections,
System.Classes,
System.Rtti,
System.SyncObjs,
ThreadSafeQueueU, System.SysUtils;
const
DEFAULT_LOG_TAG = 'main';
{$I loggerprobuildconsts.inc}
var
DefaultLoggerProMainQueueSize: Cardinal = 50000;
DefaultLoggerProAppenderQueueSize: Cardinal = 50000;
type
TLogType = (Debug = 0, Info, Warning, Error, Fatal);
TLogErrorReason = (QueueFull);
TLogErrorAction = (SkipNewest, DiscardOlder);
TLogExtendedInfo = (EIUserName, EIComputerName, EIProcessName, EIProcessID, EIDeviceID { mobile });
TLoggerProExtendedInfo = set of TLogExtendedInfo;
{ @abstract(Time rotation intervals for file appenders)
Used by WriteToFile.WithInterval() and WriteToTimeRotatingFile. }
TTimeRotationInterval = (
None, // No time-based rotation (size only)
Hourly, // Rotate every hour: app.2025120312.log
Daily, // Rotate every day: app.20251203.log
Weekly, // Rotate every week: app.2025W49.log
Monthly // Rotate every month: app.202512.log
);
{ @abstract(Represents a key-value pair for structured logging context) }
LogParam = record
Key: string;
Value: TValue;
// NOT inline on purpose: inline-expanding these at the call site would
// require every caller (sample projects, user applications, DMVC, etc.)
// to add System.Rtti to their own uses clause - just because TValue is
// declared there. Keeping them as regular class functions shields users
// from that implementation leak. The cost (one extra call) is noise
// compared to the TValue construction happening inside.
class function S(const AKey: string; const AValue: string): LogParam; static;
class function I(const AKey: string; const AValue: Integer): LogParam; static;
class function B(const AKey: string; const AValue: Boolean): LogParam; static;
class function F(const AKey: string; const AValue: Double): LogParam; static;
class function D(const AKey: string; const AValue: TDateTime): LogParam; static;
class function FmtS(const AKey: string; const AFormat: string; const AArgs: array of const): LogParam; static;
class function V(const AKey: string; const AValue: TValue): LogParam; static;
end;
LogParams = TArray<LogParam>;
{ @abstract(Function type for pluggable stack trace formatters)
Assign a function to extract stack traces using JCL, madExcept, EurekaLog, or
any other library. If no formatter is set, exception logging will only
include the exception class name and message.
Example with JCL:
@longcode(#
Log := LoggerProBuilder
.WithStackTraceFormatter(
function(E: Exception): string
begin
Result := JclLastExceptStackListToString;
end)
.WriteToConsole.Done
.Build;
#) }
TStackTraceFormatter = TFunc<Exception, string>;
{ @abstract(Represent the single log item)
Each call to some kind of log method is wrapped in a @link(TLogItem)
instance and passed down the layour of LoggerPro. }
TLogItem = class sealed
private
FType: TLogType;
FMessage: string;
FTag: string;
FTimeStamp: TDateTime;
FThreadID: TThreadID;
FContext: LogParams;
FPreRenderedContext: string;
function GetLogTypeAsString: string;
public
constructor Create(const aType: TLogType; const aMessage: string; const aTag: string); overload;
constructor Create(const aType: TLogType; const aMessage: string; const aTag: string; const aTimeStamp: TDateTime;
const aThreadID: TThreadID); overload;
constructor Create(const aType: TLogType; const aMessage: string; const aTag: string;
const aContext: LogParams); overload;
constructor Create(const aType: TLogType; const aMessage: string; const aTag: string; const aTimeStamp: TDateTime;
const aThreadID: TThreadID; const aContext: LogParams); overload;
function Clone: TLogItem;
{ @abstract(The type of the log)
Log can be one of the following types:
@unorderedlist(
@item(DEBUG)
@item(INFO)
@item(WARNING)
@item(ERROR)
@item(FATAL)
) }
property LogType: TLogType read FType;
{ @abstract(The text of the log message) }
property LogMessage: string read FMessage;
{ @abstract(The tag of the log message) }
property LogTag: string read FTag;
{ @abstract(The timestamp when the @link(TLogItem) is generated) }
property TimeStamp: TDateTime read FTimeStamp;
{ @abstract(The IDof the thread which generated the log item) }
property ThreadID: TThreadID read FThreadID;
{ @abstract(The type of the log converted in string) }
property LogTypeAsString: string read GetLogTypeAsString;
{ @abstract(The structured context key-value pairs) }
property Context: LogParams read FContext;
{ @abstract(Pre-rendered context string for fixed context optimization) }
property PreRenderedContext: string read FPreRenderedContext write FPreRenderedContext;
{ @abstract(Returns true if the log item has context data) }
function HasContext: Boolean; inline;
end;
ILogItemRenderer = interface
['{CBD22D22-C387-4A97-AD5D-4945B812FDB0}']
procedure Setup;
procedure TearDown;
function RenderLogItem(const aLogItem: TLogItem): String;
end;
TLoggerProAppenderErrorEvent = reference to procedure(const AppenderClassName: string; const aFailedLogItem: TLogItem;
const Reason: TLogErrorReason; var Action: TLogErrorAction);
TLoggerProEventsHandler = class sealed
public
OnAppenderError: TLoggerProAppenderErrorEvent;
end;
{ @abstract(Interface implemented by all the classes used as appenders) }
ILogAppender = interface
['{58AFB557-C594-4A4B-8DC9-0F13B37F60CB}']
{ @abstract(This method is internally called by LoggerPro to initialize the appender) }
procedure Setup;
{ @abstract(This method is called at each log item represented by @link(TLogItem))
The appender should be as-fast-as-it-can to handle the message, however
each appender runs in a separated thread. }
procedure WriteLog(const aLogItem: TLogItem);
{ @abstract(This method is internally called by LoggerPro to deinitialize the appender) }
procedure TearDown;
{ @abstract(Enable or disable the log appender) }
procedure SetEnabled(const Value: Boolean);
{ @abstract(Returns if the logappender is currently enabled or not) }
function IsEnabled: Boolean;
{ @abstract(Set the minimum severity level this appender will emit.
Messages whose severity is below this threshold are dropped at this
appender (but may still reach other appenders). Setting a value
below the global LogWriter <c>MinimumLevel</c> is a no-op, because
the global gate filters messages before they reach any appender. }
procedure SetMinimumLevel(const Value: TLogType);
{ @abstract(Get the minimum severity level this appender emits. }
function GetMinimumLevel: TLogType;
{ @abstract(If the appender is disabled, this method is called at each new
logitem. This method should not raise exceptions and should try to restart the appender
at specified time and only if some appropriate seconds/miutes are elapsed between the
LastErrorTimestamp. }
procedure TryToRestart(var Restarted: Boolean);
procedure SetLastErrorTimeStamp(const LastErrorTimeStamp: TDateTime);
function GetLastErrorTimeStamp: TDateTime;
property LastErrorTimeStamp: TDateTime read GetLastErrorTimeStamp write SetLastErrorTimeStamp;
end;
ELoggerPro = class(Exception)
end;
/// <summary>Raised by the JSON config facade (LoggerProFromJSONFile,
/// LoggerProFromJSONString and the underlying TLoggerProConfig).
/// Declared here so callers using only `uses LoggerPro;` can catch
/// it without pulling in LoggerPro.Config.</summary>
ELoggerProConfigError = class(ELoggerPro);
TAppenderQueue = class(TThreadSafeQueue<TLogItem>)
end;
ICustomLogWriter = interface
['{8BC2F462-E2A3-4117-BE1F-03EB31997BB4}']
function GetAppendersClassNames: TArray<string>;
function GetAppenders(const aIndex: Integer): ILogAppender;
property Appenders[const aIndex: Integer]: ILogAppender read GetAppenders;
procedure AddAppender(const aAppenders: ILogAppender);
procedure DelAppender(const aAppenders: ILogAppender);
function AppendersCount(): Integer;
// Base logging method
procedure Log(const aType: TLogType; const aMessage: string; const aTag: string); overload;
// Enqueue a pre-built log item (for internal use with pre-rendered context)
procedure EnqueueLogItem(const aLogItem: TLogItem);
// Global gate level. Reading: lowest level that will pass the gate.
// Writing: changes the gate at runtime - useful for bridges (e.g. the
// DMVC MVCFramework.Logger.UseLoggerVerbosityLevel setter) that need
// to honor a verbosity change without rebuilding the writer.
function GetMinimumLevel: TLogType;
procedure SetMinimumLevel(const aLevel: TLogType);
property MinimumLevel: TLogType read GetMinimumLevel write SetMinimumLevel;
end;
ILogWriter = interface(ICustomLogWriter)
['{A717A040-4493-458F-91B2-6F6E2AFB496F}']
{ Logging methods without tag - uses default tag }
procedure Debug(const aMessage: string); overload;
procedure Info(const aMessage: string); overload;
procedure Warn(const aMessage: string); overload;
procedure Error(const aMessage: string); overload;
procedure Fatal(const aMessage: string); overload;
{ Logging methods with explicit tag }
procedure Debug(const aMessage: string; const aTag: string); overload;
procedure Debug(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Debug(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
procedure Info(const aMessage: string; const aTag: string); overload;
procedure Info(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Info(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
procedure Warn(const aMessage: string; const aTag: string); overload;
procedure Warn(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Warn(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
procedure Error(const aMessage: string; const aTag: string); overload;
procedure Error(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Error(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
procedure Fatal(const aMessage: string; const aTag: string); overload;
procedure Fatal(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Fatal(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
{ Exception logging - logs exception with optional stack trace if provider is set }
procedure LogException(const E: Exception); overload;
procedure LogException(const E: Exception; const aMessage: string); overload;
procedure LogException(const E: Exception; const aMessage: string; const aTag: string); overload;
procedure Log(const aType: TLogType; const aMessage: string; const aTag: string); overload;
procedure Log(const aType: TLogType; const aMessage: string; const aParams: array of const; const aTag: string); overload;
procedure Log(const aType: TLogType; const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
{ @abstract(Returns a new ILogWriter with bound context. Thread-safe - creates a new instance.) }
function WithProperty(const aKey: string; const aValue: string): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: Integer): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: Boolean): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: Double): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: TDateTime): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: TValue): ILogWriter; overload;
function WithPropertyFmt(const aKey: string; const aFormat: string; const aArgs: array of const): ILogWriter;
{ @abstract(Returns a new ILogWriter with a custom default tag. Thread-safe - creates a new instance.) }
function WithDefaultTag(const aTag: string): ILogWriter;
{ @abstract(Returns a new ILogWriter with a default context. All log calls will include this context.) }
function WithDefaultContext(const aContext: array of LogParam): ILogWriter;
procedure Disable;
procedure Enable;
{ @abstract(Returns True if a message at this level would actually be
dispatched. Useful to guard expensive log-argument construction:
@longcode(#
if Log.IsDebugEnabled then
Log.Debug('Trace: %s', [ExpensiveToString]);
#)
Returns False while shutting down, while disabled, or when the level
is below the configured minimum. All wrapper writers (WithProperty,
WithDefaultTag, WithDefaultContext) delegate to the root writer so
the result reflects the true dispatch decision.) }
function IsEnabled(aLevel: TLogType): Boolean;
function IsDebugEnabled: Boolean;
function IsInfoEnabled: Boolean;
function IsWarningEnabled: Boolean;
function IsErrorEnabled: Boolean;
function IsFatalEnabled: Boolean;
{ @abstract(Forces flush and shutdown of the logger thread, regardless of reference count.
After calling Shutdown, any logging attempt will be silently ignored (Release) or Assert (Debug).
Use this in finalization to ensure all logs are written before the application exits.) }
procedure Shutdown;
end;
TLogAppenderList = TList<ILogAppender>;
TAppenderThread = class(TThread)
private
FLogAppender: ILogAppender;
FAppenderQueue: TAppenderQueue;
FFailing: Boolean;
FReadyEvent: TEvent;
procedure SetFailing(const Value: Boolean);
protected
procedure Execute; override;
type
TAppenderStatus = (BeforeSetup, Running, WaitAfterFail, ToRestart, BeforeTearDown);
public
constructor Create(aLogAppender: ILogAppender; aAppenderQueue: TAppenderQueue);
destructor Destroy; override;
{ Wait until the thread has attempted its first Setup. Guarantees that
when the caller proceeds, the appender is either Running (Setup OK)
or in WaitAfterFail (Setup failed repeatedly). Either way the thread
is scheduled and observing its queue - no log item enqueued after
this point can be lost to "thread not scheduled yet" races. }
function WaitUntilReady(aTimeoutMs: Cardinal): Boolean;
property Failing: Boolean read FFailing write SetFailing;
end;
TLoggerThread = class(TThread)
private type
TAppenderAdapter = class
private
FAppenderQueue: TAppenderQueue;
FAppenderThread: TAppenderThread;
FLogAppender: ILogAppender;
FFailsCount: Cardinal;
public
constructor Create(aAppender: ILogAppender); virtual;
destructor Destroy; override;
function EnqueueLog(const aLogItem: TLogItem): Boolean;
property Queue: TAppenderQueue read FAppenderQueue;
property FailsCount: Cardinal read FFailsCount;
function GetMinimumLevel: TLogType;
procedure Terminate;
procedure SignalTerminate;
procedure WaitForExit;
end;
TAppenderAdapterList = class(TObjectList<TAppenderAdapter>)
public
constructor Create;
end;
private
FQueue: TThreadSafeQueue<TLogItem>;
FAppenders: TLogAppenderList;
FEventsHandlers: TLoggerProEventsHandler;
FAppendersDecorators: TObjectList<TAppenderAdapter>;
function BuildAppenderAdapters: TAppenderAdapterList;
procedure DispatchLogItem(const aLogItem: TLogItem);
procedure DoOnAppenderError(const FailAppenderClassName: string; const aFailedLogItem: TLogItem; const aReason: TLogErrorReason;
var aAction: TLogErrorAction);
procedure SetEventsHandlers(const Value: TLoggerProEventsHandler);
protected
procedure Execute; override;
procedure DoTerminate; override;
public
constructor Create(aAppenders: TLogAppenderList);
destructor Destroy; override;
property EventsHandlers: TLoggerProEventsHandler read FEventsHandlers write SetEventsHandlers;
property LogWriterQueue: TThreadSafeQueue < TLogItem > read FQueue;
end;
TLoggerProInterfacedObject = class(TInterfacedObject)
protected
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
end;
TCustomLogWriter = class(TLoggerProInterfacedObject, ICustomLogWriter)
strict private
FLoggerThread: TLoggerThread;
FLogAppenders: TLogAppenderList;
FFreeAllowed: Boolean;
FLock: TObject;
FStackTraceFormatter: TStackTraceFormatter;
function GetAppendersClassNames: TArray<string>;
protected
FEnabled: Boolean;
FLogLevel: TLogType;
FShuttingDown: Boolean;
procedure Initialize(const aEventsHandler: TLoggerProEventsHandler);
function FormatExceptionMessage(const E: Exception; const aMessage: string): string;
public
constructor Create(const aLogLevel: TLogType = TLogType.Debug); overload;
constructor Create(const aLogAppenders: TLogAppenderList; const aLogLevel: TLogType = TLogType.Debug); overload;
destructor Destroy; override;
function GetAppenders(const aIndex: Integer): ILogAppender;
procedure AddAppender(const aAppender: ILogAppender);
procedure DelAppender(const aAppender: ILogAppender);
function AppendersCount(): Integer;
procedure Log(const aType: TLogType; const aMessage: string; const aTag: string); overload;
procedure Log(const aType: TLogType; const aMessage: string; const aTag: string; const aContext: LogParams); overload;
procedure EnqueueLogItem(const aLogItem: TLogItem);
procedure Disable; virtual;
procedure Enable; virtual;
procedure Shutdown; virtual;
function GetMinimumLevel: TLogType;
procedure SetMinimumLevel(const aLevel: TLogType);
property StackTraceFormatter: TStackTraceFormatter read FStackTraceFormatter write FStackTraceFormatter;
property MinimumLevel: TLogType read GetMinimumLevel write SetMinimumLevel;
end;
TLogWriter = class(TCustomLogWriter, ILogWriter)
public
{ Logging methods without tag - uses DEFAULT_LOG_TAG }
procedure Debug(const aMessage: string); overload;
procedure Info(const aMessage: string); overload;
procedure Warn(const aMessage: string); overload;
procedure Error(const aMessage: string); overload;
procedure Fatal(const aMessage: string); overload;
{ Logging methods with explicit tag }
procedure Debug(const aMessage: string; const aTag: string); overload;
procedure Debug(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Debug(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
procedure Info(const aMessage: string; const aTag: string); overload;
procedure Info(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Info(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
procedure Warn(const aMessage: string; const aTag: string); overload;
procedure Warn(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Warn(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
procedure Error(const aMessage: string; const aTag: string); overload;
procedure Error(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Error(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
procedure Fatal(const aMessage: string; const aTag: string); overload;
procedure Fatal(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Fatal(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
procedure LogException(const E: Exception); overload;
procedure LogException(const E: Exception; const aMessage: string); overload;
procedure LogException(const E: Exception; const aMessage: string; const aTag: string); overload;
procedure Log(const aType: TLogType; const aMessage: string; const aParams: array of const; const aTag: string); overload;
procedure Log(const aType: TLogType; const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
function WithProperty(const aKey: string; const aValue: string): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: Integer): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: Boolean): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: Double): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: TDateTime): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: TValue): ILogWriter; overload;
function WithPropertyFmt(const aKey: string; const aFormat: string; const aArgs: array of const): ILogWriter;
function WithDefaultTag(const aTag: string): ILogWriter;
function WithDefaultContext(const aContext: array of LogParam): ILogWriter;
function IsEnabled(aLevel: TLogType): Boolean;
function IsDebugEnabled: Boolean;
function IsInfoEnabled: Boolean;
function IsWarningEnabled: Boolean;
function IsErrorEnabled: Boolean;
function IsFatalEnabled: Boolean;
end;
{ @abstract(Wrapper for ILogWriter with bound context) }
TLogWriterWithContext = class(TInterfacedObject, ILogWriter)
private
FInner: ILogWriter;
FContext: LogParams;
FPreRenderedContext: string;
function MergeContext(const aContext: array of LogParam): LogParams;
class function RenderContextToString(const AContext: LogParams): string; static;
public
constructor Create(const AInner: ILogWriter; const AContext: LogParams);
// ICustomLogWriter
function GetAppendersClassNames: TArray<string>;
function GetAppenders(const aIndex: Integer): ILogAppender;
procedure AddAppender(const aAppenders: ILogAppender);
procedure DelAppender(const aAppenders: ILogAppender);
function AppendersCount(): Integer;
procedure Log(const aType: TLogType; const aMessage: string; const aTag: string); overload;
procedure EnqueueLogItem(const aLogItem: TLogItem);
function GetMinimumLevel: TLogType;
procedure SetMinimumLevel(const aLevel: TLogType);
// ILogWriter - without tag (uses DEFAULT_LOG_TAG)
procedure Debug(const aMessage: string); overload;
procedure Info(const aMessage: string); overload;
procedure Warn(const aMessage: string); overload;
procedure Error(const aMessage: string); overload;
procedure Fatal(const aMessage: string); overload;
// ILogWriter - with explicit tag
procedure Debug(const aMessage: string; const aTag: string); overload;
procedure Debug(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Debug(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
procedure Info(const aMessage: string; const aTag: string); overload;
procedure Info(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Info(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
procedure Warn(const aMessage: string; const aTag: string); overload;
procedure Warn(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Warn(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
procedure Error(const aMessage: string; const aTag: string); overload;
procedure Error(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Error(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
procedure Fatal(const aMessage: string; const aTag: string); overload;
procedure Fatal(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Fatal(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
procedure LogException(const E: Exception); overload;
procedure LogException(const E: Exception; const aMessage: string); overload;
procedure LogException(const E: Exception; const aMessage: string; const aTag: string); overload;
procedure Log(const aType: TLogType; const aMessage: string; const aParams: array of const; const aTag: string); overload;
procedure Log(const aType: TLogType; const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
function WithProperty(const aKey: string; const aValue: string): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: Integer): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: Boolean): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: Double): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: TDateTime): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: TValue): ILogWriter; overload;
function WithPropertyFmt(const aKey: string; const aFormat: string; const aArgs: array of const): ILogWriter;
function WithDefaultTag(const aTag: string): ILogWriter;
function WithDefaultContext(const aContext: array of LogParam): ILogWriter;
function IsEnabled(aLevel: TLogType): Boolean;
function IsDebugEnabled: Boolean;
function IsInfoEnabled: Boolean;
function IsWarningEnabled: Boolean;
function IsErrorEnabled: Boolean;
function IsFatalEnabled: Boolean;
procedure Disable;
procedure Enable;
procedure Shutdown;
end;
{ @abstract(Wrapper for ILogWriter with custom default tag) }
TLogWriterWithDefaultTag = class(TInterfacedObject, ILogWriter)
private
FInner: ILogWriter;
FDefaultTag: string;
public
constructor Create(const AInner: ILogWriter; const ADefaultTag: string);
// ICustomLogWriter
function GetAppendersClassNames: TArray<string>;
function GetAppenders(const aIndex: Integer): ILogAppender;
procedure AddAppender(const aAppenders: ILogAppender);
procedure DelAppender(const aAppenders: ILogAppender);
function AppendersCount(): Integer;
procedure Log(const aType: TLogType; const aMessage: string; const aTag: string); overload;
procedure EnqueueLogItem(const aLogItem: TLogItem);
function GetMinimumLevel: TLogType;
procedure SetMinimumLevel(const aLevel: TLogType);
// ILogWriter - without tag (uses FDefaultTag)
procedure Debug(const aMessage: string); overload;
procedure Info(const aMessage: string); overload;
procedure Warn(const aMessage: string); overload;
procedure Error(const aMessage: string); overload;
procedure Fatal(const aMessage: string); overload;
// ILogWriter - with explicit tag
procedure Debug(const aMessage: string; const aTag: string); overload;
procedure Debug(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Debug(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
procedure Info(const aMessage: string; const aTag: string); overload;
procedure Info(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Info(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
procedure Warn(const aMessage: string; const aTag: string); overload;
procedure Warn(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Warn(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
procedure Error(const aMessage: string; const aTag: string); overload;
procedure Error(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Error(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
procedure Fatal(const aMessage: string; const aTag: string); overload;
procedure Fatal(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Fatal(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
procedure LogException(const E: Exception); overload;
procedure LogException(const E: Exception; const aMessage: string); overload;
procedure LogException(const E: Exception; const aMessage: string; const aTag: string); overload;
procedure Log(const aType: TLogType; const aMessage: string; const aParams: array of const; const aTag: string); overload;
procedure Log(const aType: TLogType; const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
function WithProperty(const aKey: string; const aValue: string): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: Integer): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: Boolean): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: Double): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: TDateTime): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: TValue): ILogWriter; overload;
function WithPropertyFmt(const aKey: string; const aFormat: string; const aArgs: array of const): ILogWriter;
function WithDefaultTag(const aTag: string): ILogWriter;
function WithDefaultContext(const aContext: array of LogParam): ILogWriter;
function IsEnabled(aLevel: TLogType): Boolean;
function IsDebugEnabled: Boolean;
function IsInfoEnabled: Boolean;
function IsWarningEnabled: Boolean;
function IsErrorEnabled: Boolean;
function IsFatalEnabled: Boolean;
procedure Disable;
procedure Enable;
procedure Shutdown;
end;
{ @abstract(Wrapper for ILogWriter with default context) }
TLogWriterWithDefaultContext = class(TInterfacedObject, ILogWriter)
private
FInner: ILogWriter;
FDefaultContext: LogParams;
function MergeContext(const aContext: array of LogParam): LogParams;
public
constructor Create(const AInner: ILogWriter; const ADefaultContext: array of LogParam);
// ICustomLogWriter
function GetAppendersClassNames: TArray<string>;
function GetAppenders(const aIndex: Integer): ILogAppender;
procedure AddAppender(const aAppenders: ILogAppender);
procedure DelAppender(const aAppenders: ILogAppender);
function AppendersCount(): Integer;
procedure Log(const aType: TLogType; const aMessage: string; const aTag: string); overload;
procedure EnqueueLogItem(const aLogItem: TLogItem);
function GetMinimumLevel: TLogType;
procedure SetMinimumLevel(const aLevel: TLogType);
// Senza tag (usa tag predefinito 'main')
procedure Debug(const aMessage: string); overload;
procedure Info(const aMessage: string); overload;
procedure Warn(const aMessage: string); overload;
procedure Error(const aMessage: string); overload;
procedure Fatal(const aMessage: string); overload;
// Con tag esplicito
procedure Debug(const aMessage: string; const aTag: string); overload;
procedure Debug(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Debug(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
procedure Info(const aMessage: string; const aTag: string); overload;
procedure Info(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Info(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
procedure Warn(const aMessage: string; const aTag: string); overload;
procedure Warn(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Warn(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
procedure Error(const aMessage: string; const aTag: string); overload;
procedure Error(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Error(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
procedure Fatal(const aMessage: string; const aTag: string); overload;
procedure Fatal(const aMessage: string; const aParams: array of TVarRec; const aTag: string); overload;
procedure Fatal(const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
procedure LogException(const E: Exception); overload;
procedure LogException(const E: Exception; const aMessage: string); overload;
procedure LogException(const E: Exception; const aMessage: string; const aTag: string); overload;
procedure Log(const aType: TLogType; const aMessage: string; const aParams: array of const; const aTag: string); overload;
procedure Log(const aType: TLogType; const aMessage: string; const aTag: string; const aContext: array of LogParam); overload;
function WithProperty(const aKey: string; const aValue: string): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: Integer): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: Boolean): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: Double): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: TDateTime): ILogWriter; overload;
function WithProperty(const aKey: string; const aValue: TValue): ILogWriter; overload;
function WithPropertyFmt(const aKey: string; const aFormat: string; const aArgs: array of const): ILogWriter;
function WithDefaultTag(const aTag: string): ILogWriter;
function WithDefaultContext(const aContext: array of LogParam): ILogWriter;
function IsEnabled(aLevel: TLogType): Boolean;
function IsDebugEnabled: Boolean;
function IsInfoEnabled: Boolean;
function IsWarningEnabled: Boolean;
function IsErrorEnabled: Boolean;
function IsFatalEnabled: Boolean;
procedure Disable;
procedure Enable;
procedure Shutdown;
end;
TOnAppenderLogRow = reference to procedure(const LogItem: TLogItem; out LogRow: string);
TLoggerProAppenderBase = class abstract(TInterfacedObject, ILogAppender)
private
FLogLevel: TLogType;
FEnabled: Boolean;
FLastErrorTimeStamp: TDateTime;
FFormatSettings: TFormatSettings;
protected
FOnLogRow: TOnAppenderLogRow;
FLogItemRenderer: ILogItemRenderer;
property FormatSettings: TFormatSettings read FFormatSettings;
property LogItemRenderer: ILogItemRenderer read FLogItemRenderer;
public
constructor Create(ALogItemRenderer: ILogItemRenderer); overload; virtual;
constructor Create; overload; virtual;
procedure Setup; virtual;
function FormatLog(const ALogItem: TLogItem): string; virtual;
procedure WriteLog(const aLogItem: TLogItem); virtual; abstract;
procedure TearDown; virtual;
procedure TryToRestart(var Restarted: Boolean); virtual;
procedure SetMinimumLevel(const Value: TLogType);
function GetMinimumLevel: TLogType; inline;
procedure SetLastErrorTimeStamp(const Value: TDateTime);
function GetLastErrorTimeStamp: TDateTime;
procedure SetEnabled(const Value: Boolean);
function IsEnabled: Boolean;
property MinimumLevel: TLogType read GetMinimumLevel write SetMinimumLevel;
property Enabled: Boolean read IsEnabled write SetEnabled;
property OnLogRow: TOnAppenderLogRow read FOnLogRow write FOnLogRow;
end;
{ @abstract(Builds a new ILogWriter instance. Call this global function to start logging like a pro.)
Here's a sample unit that you can use in your code
@longcode(#
unit LoggerProConfig;
interface
uses
LoggerPro;
function Log: ILogWriter;
implementation
uses
LoggerPro.FileAppender;
var
_Log: ILogWriter;
function Log: ILogWriter;
begin
Result := _Log;
end;
initialization
//If you need other appenders, feel free to add them here in the array
_Log := BuildLogWriter([TLoggerProFileAppender.Create(10, 5)]);
end.
#)
Add this unit to your project, then when you need to use the logger, include
the unit and call one of the followings:
@unorderedlist(
@item(Log.Debug('This is a debug message', 'tag1'))
@item(Log.Info('This is an information message', 'tag1'))
@item(Log.Warn('This is a warning message', 'tag1'))
@item(Log.Error('This is an error message', 'tag1'))
@item(Log.Fatal('This is a fatal message', 'tag1'))
)
}
TLogItemRenderer = class abstract(TInterfacedObject, ILogItemRenderer)
protected
procedure Setup; virtual;
procedure TearDown; virtual;
function RenderLogItem(const aLogItem: TLogItem): String; virtual;abstract;
public
class function GetDefaultLogItemRenderer: ILogItemRenderer;
end;
TLogItemRendererClass = class of TLogItemRenderer;
{ @abstract(Callback type invoked after a log file is rotated.)
The callback receives the full path of the rotated file.
@bold(Important:) This callback runs on the logger thread.
Do not perform long-running operations directly; instead,
kick off async work (e.g., compress, upload, archive).
}
TFileRotateCallback = reference to procedure(const aRotatedFileName: string);
{ Callback signature for receiving log items }
TLogItemCallback = reference to procedure(const aLogItem: TLogItem; const aFormattedMessage: string);
{ Webhook appender body content type }
TWebhookContentType = (JSON, PlainText);
/// <summary>Where the API key value is carried on every POST.</summary>
TWebhookAPIKeyLocation = (
/// <summary>As an HTTP request header (default; header name configurable,
/// defaults to <c>X-API-Key</c>). Works with API Gateway / Azure APIM /
/// Kong / custom REST endpoints that read keys from headers.</summary>
Header,
/// <summary>As a query-string parameter (parameter name configurable,
/// defaults to <c>api_key</c>). Useful for services that accept auth
/// via URL (some cloud logging webhooks, legacy endpoints).</summary>
QueryString);
{ Per-element color / style scheme (colorama-style: only colors, no
suffixes; the renderer auto-appends STYLE_RESETALL after every colored
token and at end of line, so color bleed is impossible).
Each field holds a ready-made ANSI prefix string - bright, dim,
background, 256-color, true color, or empty for no effect. }
TLogColorScheme = record
PrefixColor: string;
SeparatorColor: string;
TimestampColor: string;
ThreadIDColor: string;
TagColor: string;
MessageColor: string;
LevelColor: array [TLogType] of string;
ContextKeyColor: string;
ContextValueColor: string;
end;
/// <summary>
/// Built-in color-scheme presets for the Gin-style console renderer.
/// Namespaced like Fore / Back / Style - use LogColorSchemes.GinBadge,
/// LogColorSchemes.Monochrome, etc. Pass to .WithColorScheme(LogColorSchemes.X) in the
/// Builder.
/// </summary>
LogColorSchemes = record
public
/// <summary>Gin-inspired classic: foreground-only level colors,
/// gray timestamp, cyan tag. Default when .WithColors is used.</summary>
class function Default: TLogColorScheme; static;
/// <summary>All fields empty - renders pure plain text, no ANSI.
/// Used automatically when stdout is piped / redirected.</summary>
class function Monochrome: TLogColorScheme; static;
/// <summary>Colored-background level badges (INFO=green bg,
/// ERROR=red bg, etc.) - looks like Gin's HTTP status-code badges.</summary>
class function GinBadge: TLogColorScheme; static;
/// <summary>All metadata dim gray, only the level word retains
/// color. Best signal-to-noise ratio for busy production logs.</summary>
class function GinMinimal: TLogColorScheme; static;
/// <summary>Saturated rainbow - one loud color per field. For demos
/// or screenshots; not recommended for long reading sessions.</summary>
class function GinVibrant: TLogColorScheme; static;
/// <summary>Midnight dark palette: purple prefix, magenta tag, green
/// context, muted gray metadata. Easy on the eyes for long sessions on
/// a dark terminal.</summary>
class function Midnight: TLogColorScheme; static;
/// <summary>Nord theme: cool arctic blues and cyans, muted warnings.
/// Low-contrast, calm; good for ambient logging on a dark background.</summary>
class function Nord: TLogColorScheme; static;
/// <summary>The Matrix: every field bright green, levels distinguished
/// by background badges. Pure nostalgia / ASCII-art demos.</summary>
class function Matrix: TLogColorScheme; static;
/// <summary>Amber CRT: warm 80s terminal - orange/yellow metadata,
/// red errors. Looks great on a true black terminal background.</summary>
class function Amber: TLogColorScheme; static;
/// <summary>Ocean: layered blues and cyans, teal tag, bright cyan
/// values. Cool and high-contrast without being loud.</summary>
class function Ocean: TLogColorScheme; static;
/// <summary>Cyberpunk neon: hot magenta prefix, cyan tag, yellow values,
/// level badges on vivid backgrounds. Loud, saturated, nightlife.</summary>
class function Cyberpunk: TLogColorScheme; static;
end;
{ ============ Builder interfaces ============ }
ILoggerProBuilder = interface;
{ Base interface for all appender configurators }
IAppenderConfigurator = interface
['{A1B2C3D4-E5F6-4A5B-8C9D-0E1F2A3B4C5D}']
function Done: ILoggerProBuilder;
end;
{ Console appender configurator }
IConsoleAppenderConfigurator = interface(IAppenderConfigurator)
['{B2C3D4E5-F6A7-5B6C-9D0E-1F2A3B4C5D6E}']
function WithMinimumLevel(aLogLevel: TLogType): IConsoleAppenderConfigurator;
function WithRenderer(aRenderer: ILogItemRenderer): IConsoleAppenderConfigurator; overload;
function WithRenderer(const aRendererName: string): IConsoleAppenderConfigurator; overload;
function WithUTF8Output: IConsoleAppenderConfigurator;
/// <summary>Enable per-field rich coloring (dim timestamp / thread ID,
/// level in level-specific color, cyan tag, green/yellow key=value).
/// Replaces the appender's whole-line coloring with the renderer's
/// in-line ANSI codes. Auto-degrades to monochrome when stdout is
/// redirected to a file or pipe.</summary>
function WithColors: IConsoleAppenderConfigurator;
/// <summary>Like WithColors but with a user-supplied scheme. Useful to
/// customize per-level colors, tag color, key/value colors, or
/// background highlights.</summary>
function WithColorScheme(const aScheme: TLogColorScheme): IConsoleAppenderConfigurator;
/// <summary>Prepend a bracketed source marker to every colored log
/// line (Gin-style [GIN] pattern): [MYAPP] 2026/04/18 - 17:33:42 | ...
/// Default is empty string = no prefix (line starts at the date).
/// Useful when multiple processes or modules aggregate into the same
/// console/pipe stream and you need to distinguish them visually.</summary>
function WithPrefix(const aPrefix: string): IConsoleAppenderConfigurator;
/// <summary>Windows only, GUI apps only. Force AllocConsole instead of
/// attaching to the parent console. Use this when launching a GUI app
/// from the Delphi IDE so a console window actually pops up - otherwise
/// AttachConsole binds to bds.exe's invisible console and you see
/// nothing. No effect for console-subsystem apps (IsConsole = True) or
/// on POSIX.</summary>
function WithForceNewConsole: IConsoleAppenderConfigurator;
end;
{ Simple console appender configurator }
ISimpleConsoleAppenderConfigurator = interface(IAppenderConfigurator)
['{B2C3D4E5-F6A7-5B6C-9D0E-1F2A3B4C5D6F}']
function WithMinimumLevel(aLogLevel: TLogType): ISimpleConsoleAppenderConfigurator;
function WithUTF8Output: ISimpleConsoleAppenderConfigurator;
/// <summary>Write log lines to stderr instead of stdout. Typical use
/// case: MCP servers and Unix daemons where stdout carries protocol or
/// data and diagnostic output belongs on stderr.</summary>
function WithStdErr: ISimpleConsoleAppenderConfigurator;
end;
{ File appender configurator }
IFileAppenderConfigurator = interface(IAppenderConfigurator)
['{C3D4E5F6-A7B8-6C7D-0E1F-2A3B4C5D6E7F}']
function WithLogsFolder(const aLogsFolder: string): IFileAppenderConfigurator;
function WithFileBaseName(const aFileBaseName: string): IFileAppenderConfigurator;
function WithMaxBackupFiles(aMaxBackupFiles: Integer): IFileAppenderConfigurator;
function WithMaxFileSizeInKB(aMaxFileSizeInKB: Integer): IFileAppenderConfigurator;
function WithInterval(aInterval: TTimeRotationInterval): IFileAppenderConfigurator;
function WithFileFormat(const aFileFormat: string): IFileAppenderConfigurator;
function WithMaxRetainedFiles(aMaxFiles: Integer): IFileAppenderConfigurator;
function WithMinimumLevel(aLogLevel: TLogType): IFileAppenderConfigurator;
function WithEncoding(aEncoding: TEncoding): IFileAppenderConfigurator;
function WithRenderer(aRenderer: ILogItemRenderer): IFileAppenderConfigurator; overload;
function WithRenderer(const aRendererName: string): IFileAppenderConfigurator; overload;
function WithOnAfterRotate(aCallback: TFileRotateCallback): IFileAppenderConfigurator;
end;
{ JSONL file appender configurator }
IJSONLFileAppenderConfigurator = interface(IAppenderConfigurator)
['{D4E5F6A7-B8C9-7D8E-1F2A-3B4C5D6E7F8A}']
function WithLogsFolder(const aLogsFolder: string): IJSONLFileAppenderConfigurator;
function WithFileBaseName(const aFileBaseName: string): IJSONLFileAppenderConfigurator;
function WithMaxBackupFiles(aMaxBackupFiles: Integer): IJSONLFileAppenderConfigurator;
function WithMaxFileSizeInKB(aMaxFileSizeInKB: Integer): IJSONLFileAppenderConfigurator;
function WithMinimumLevel(aLogLevel: TLogType): IJSONLFileAppenderConfigurator;
end;
/// <summary>
/// Configurator for the time-rotating file appender.
/// Creates a new log file each time the configured time interval rolls over
/// (e.g. every hour, day, week, or month).
/// <code>
/// Log := LoggerProBuilder
/// .WriteToTimeRotatingFile
/// .WithInterval(TTimeRotationInterval.Hourly)
/// .WithLogsFolder('logs')
/// .WithFileBaseName('myapp')
/// .WithMaxBackupFiles(48)
/// .Done
/// .Build;
/// </code>
/// </summary>
ITimeRotatingFileAppenderConfigurator = interface(IAppenderConfigurator)
['{E5F6A7B8-C9D0-8E9F-2A3B-4C5D6E7F8A9B}']
/// <summary>Sets the rotation interval. Determines how often a new log file
/// is created. Values: Hourly, Daily (default), Weekly, Monthly.
/// File name includes a timestamp suffix matching the interval:
/// Hourly -> myapp.2026032614.log
/// Daily -> myapp.20260326.log