-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathu_Logger.pas
More file actions
100 lines (78 loc) · 2.27 KB
/
Copy pathu_Logger.pas
File metadata and controls
100 lines (78 loc) · 2.27 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
unit u_Logger;
(*
Copyright © 2025, 2026
William Meyer All rights reserved.
Simple memo-backed logger used throughout SBOMgen.
SysLog is a global instance initialised at application startup.
The host form assigns SysLog.Memo before any logging occurs.
All methods guard against an unassigned Memo and are safe to
call during startup before the form is fully constructed.
*)
interface
uses
RzEdit;
type
/// <summary>
/// Memo-backed logger. Writes timestamped entries to an injected
/// TRzMemo. Safe to call before Memo is assigned — entries are
/// silently discarded if no Memo has been set.
/// </summary>
TLogger = class
private
FMemo: TRzMemo;
procedure SetMemo(const AValue: TRzMemo);
public
constructor Create;
/// <summary>Appends AText as a new line in the memo.</summary>
procedure Add(const AText: string);
/// <summary>Formats and appends a line using the supplied format string and arguments.</summary>
procedure AddFormat(const AFormat: string; const AArgs: array of const);
/// <summary>Clears all content from the memo.</summary>
procedure Clear;
/// <summary>Returns the current line count of the memo.</summary>
function GetCount: Integer;
/// <summary>The TRzMemo this logger writes to. Must be assigned before logging begins.</summary>
property Memo: TRzMemo read FMemo write SetMemo;
/// <summary>Current line count of the memo.</summary>
property Count: Integer read GetCount;
end;
// Global logger instance. Initialised in the project source;
// Memo assigned by the host form in its OnCreate handler.
var
SysLog: TLogger;
implementation
uses
System.SysUtils;
{ TLogger }
constructor TLogger.Create;
begin
inherited Create;
end;
procedure TLogger.Add(const AText: string);
begin
if not Assigned(FMemo) then
Exit;
FMemo.Lines.Add(AText);
end;
procedure TLogger.AddFormat(const AFormat: string;
const AArgs: array of const);
begin
Add(Format(AFormat, AArgs));
end;
procedure TLogger.Clear;
begin
if not Assigned(FMemo) then
Exit;
FMemo.Clear;
end;
function TLogger.GetCount: Integer;
begin
if not Assigned(FMemo) then
Exit(0);
Result := FMemo.Lines.Count;
end;
procedure TLogger.SetMemo(const AValue: TRzMemo);
begin
FMemo := AValue;
end;
end.