|
|
@@ -84,16 +84,21 @@ type |
|
|
TutlFileLogger = class(TutlInterfaceNoRefCount, IutlLogConsumer) |
|
|
TutlFileLogger = class(TutlInterfaceNoRefCount, IutlLogConsumer) |
|
|
private |
|
|
private |
|
|
fStream: TFileStream; |
|
|
fStream: TFileStream; |
|
|
fAutoFlush: boolean; |
|
|
|
|
|
|
|
|
fAutoFlush: Boolean; |
|
|
|
|
|
fAutoFree: Boolean; |
|
|
|
|
|
procedure SetAutoFree(aValue: Boolean); |
|
|
|
|
|
protected |
|
|
|
|
|
function _Release : longint;{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF}; override; |
|
|
protected |
|
|
protected |
|
|
procedure WriteLog(const aLogger: TutlLogger; const aTime: TDateTime; const aLevel: TutlLogLevel; const aSender: string; const aMessage: String); |
|
|
procedure WriteLog(const aLogger: TutlLogger; const aTime: TDateTime; const aLevel: TutlLogLevel; const aSender: string; const aMessage: String); |
|
|
public |
|
|
public |
|
|
constructor Create(const aFilename: String; const aMode: TutlFileLoggerMode); |
|
|
|
|
|
|
|
|
constructor Create(const aFilename: String; const aMode: TutlFileLoggerMode; const aAutoFree: Boolean = false); |
|
|
destructor Destroy; override; |
|
|
destructor Destroy; override; |
|
|
|
|
|
|
|
|
procedure Flush(); overload; |
|
|
procedure Flush(); overload; |
|
|
published |
|
|
published |
|
|
property AutoFlush:boolean read fAutoFlush write fAutoFlush; |
|
|
|
|
|
|
|
|
property AutoFlush: Boolean read fAutoFlush write fAutoFlush; |
|
|
|
|
|
property AutoFree: Boolean read fAutoFree write SetAutoFree; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
{ TutlConsoleLogger } |
|
|
{ TutlConsoleLogger } |
|
|
@@ -172,6 +177,22 @@ begin |
|
|
{$ENDIF} |
|
|
{$ENDIF} |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
|
|
|
procedure TutlFileLogger.SetAutoFree(aValue: Boolean); |
|
|
|
|
|
begin |
|
|
|
|
|
if fAutoFree = aValue then |
|
|
|
|
|
Exit; |
|
|
|
|
|
fAutoFree := aValue; |
|
|
|
|
|
if (fRefCount <= 0) and fAutoFree then |
|
|
|
|
|
Free; |
|
|
|
|
|
end; |
|
|
|
|
|
|
|
|
|
|
|
function TutlFileLogger._Release : longint;{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF}; |
|
|
|
|
|
begin |
|
|
|
|
|
result := inherited _Release; |
|
|
|
|
|
if (Result <= 0) and fAutoFree then |
|
|
|
|
|
Free; |
|
|
|
|
|
end; |
|
|
|
|
|
|
|
|
procedure TutlFileLogger.WriteLog(const aLogger: TutlLogger; const aTime: TDateTime; |
|
|
procedure TutlFileLogger.WriteLog(const aLogger: TutlLogger; const aTime: TDateTime; |
|
|
const aLevel: TutlLogLevel; const aSender: string; const aMessage: String); |
|
|
const aLevel: TutlLogLevel; const aSender: string; const aMessage: String); |
|
|
var |
|
|
var |
|
|
@@ -185,7 +206,7 @@ begin |
|
|
end; |
|
|
end; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
constructor TutlFileLogger.Create(const aFilename: String; const aMode: TutlFileLoggerMode); |
|
|
|
|
|
|
|
|
constructor TutlFileLogger.Create(const aFilename: String; const aMode: TutlFileLoggerMode; const aAutoFree: Boolean = false); |
|
|
const |
|
|
const |
|
|
RIGHTS: Cardinal = {$IFNDEF UNIX}fmShareDenyWrite{$ELSE}%0100100100 {-r--r--r--}{$ENDIF}; |
|
|
RIGHTS: Cardinal = {$IFNDEF UNIX}fmShareDenyWrite{$ELSE}%0100100100 {-r--r--r--}{$ENDIF}; |
|
|
begin |
|
|
begin |
|
|
@@ -204,7 +225,8 @@ begin |
|
|
end else |
|
|
end else |
|
|
raise; |
|
|
raise; |
|
|
end; |
|
|
end; |
|
|
AutoFlush:=true; |
|
|
|
|
|
|
|
|
AutoFlush := true; |
|
|
|
|
|
fAutoFree := aAutoFree; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
destructor TutlFileLogger.Destroy; |
|
|
destructor TutlFileLogger.Destroy; |
|
|
@@ -272,13 +294,16 @@ end; |
|
|
procedure TutlLogger.RegisterConsumer(const aConsumer: IutlLogConsumer; const aFilter: TutlLogLevels); |
|
|
procedure TutlLogger.RegisterConsumer(const aConsumer: IutlLogConsumer; const aFilter: TutlLogLevels); |
|
|
var |
|
|
var |
|
|
ll: TutlLogLevel; |
|
|
ll: TutlLogLevel; |
|
|
|
|
|
tmp: IutlLogConsumer; |
|
|
begin |
|
|
begin |
|
|
fConsumersLock.Acquire; |
|
|
fConsumersLock.Acquire; |
|
|
try |
|
|
try |
|
|
|
|
|
tmp := aConsumer; // HACK: store interface due to ref count bug :/ |
|
|
for ll:= low(ll) to high(ll) do |
|
|
for ll:= low(ll) to high(ll) do |
|
|
if (ll in aFilter) and (fConsumers[ll].IndexOf(aConsumer)<0) then |
|
|
|
|
|
fConsumers[ll].Add(aConsumer); |
|
|
|
|
|
|
|
|
if (ll in aFilter) and (fConsumers[ll].IndexOf(tmp) < 0) then |
|
|
|
|
|
fConsumers[ll].Add(tmp); |
|
|
finally |
|
|
finally |
|
|
|
|
|
tmp := nil; |
|
|
fConsumersLock.Release; |
|
|
fConsumersLock.Release; |
|
|
end; |
|
|
end; |
|
|
if llDebug in aFilter then |
|
|
if llDebug in aFilter then |
|
|
@@ -291,7 +316,7 @@ var |
|
|
begin |
|
|
begin |
|
|
fConsumersLock.Acquire; |
|
|
fConsumersLock.Acquire; |
|
|
try |
|
|
try |
|
|
for ll:= low(ll) to high(ll) do |
|
|
|
|
|
|
|
|
for ll := low(ll) to high(ll) do |
|
|
if ll in aFilter then |
|
|
if ll in aFilter then |
|
|
fConsumers[ll].Remove(aConsumer); |
|
|
fConsumers[ll].Remove(aConsumer); |
|
|
finally |
|
|
finally |
|
|
|