我在想; 您更喜欢Delphi的哪些日志库?
如果你使用了多个,请尝试添加一个推理,为什么你喜欢一个而不是另一个.
我会在这个问题上添加建议以保持可读性.
我刚刚编写了自己的日志框架(非常轻量级,不需要大型日志框架).它由一个接口ILogger和许多实现该接口的类组成.我有一个问题是TGUILogger,它将TStrings作为日志记录目标,并将日志记录与主线程同步,以便列表框的Items成员可以用作目标.
type
ILogger = Interface (IInterface)
procedure Log (const LogString : String; LogLevel : TLogLevel);
procedure SetLoggingLevel (LogLevel : TLogLevel);
end;
type
TGUILogger = class (TInterfacedObject, ILogger)
public
constructor Create (Target : TStrings);
procedure Log (const LogString : String; LogLevel : TLogLevel);
procedure SetLoggingLevel (LogLevel : TLogLevel);
private
procedure PerformLogging;
end;
procedure TGUILogger.Log (const LogString : String; LogLevel : TLogLevel);
begin
TMonitor.Enter (Self);
try
FLogString := GetDateTimeString + ' ' + LogString;
TThread.Synchronize (TThread.CurrentThread, PerformLogging);
finally
TMonitor.Exit (Self);
end;
end; …
Run Code Online (Sandbox Code Playgroud)