Преглед на файлове

* refactored TutlEventManager

* added ref count for TutlFileLogger (auto free on application exit)
master
Bergmann89 преди 10 години
родител
ревизия
f24d6090b1
променени са 2 файла, в които са добавени 529 реда и са изтрити 528 реда
  1. +496
    -520
      uutlEventManager.pas
  2. +33
    -8
      uutlLogger.pas

+ 496
- 520
uutlEventManager.pas
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 33
- 8
uutlLogger.pas Целия файл

@@ -84,16 +84,21 @@ type
TutlFileLogger = class(TutlInterfaceNoRefCount, IutlLogConsumer)
private
fStream: TFileStream;
fAutoFlush: boolean;
fAutoFlush: Boolean;
fAutoFree: Boolean;
procedure SetAutoFree(aValue: Boolean);
protected
function _Release : longint;{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF}; override;
protected
procedure WriteLog(const aLogger: TutlLogger; const aTime: TDateTime; const aLevel: TutlLogLevel; const aSender: string; const aMessage: String);
public
constructor Create(const aFilename: String; const aMode: TutlFileLoggerMode);
constructor Create(const aFilename: String; const aMode: TutlFileLoggerMode; const aAutoFree: Boolean = false);
destructor Destroy; override;

procedure Flush(); overload;
published
property AutoFlush:boolean read fAutoFlush write fAutoFlush;
property AutoFlush: Boolean read fAutoFlush write fAutoFlush;
property AutoFree: Boolean read fAutoFree write SetAutoFree;
end;

{ TutlConsoleLogger }
@@ -172,6 +177,22 @@ begin
{$ENDIF}
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;
const aLevel: TutlLogLevel; const aSender: string; const aMessage: String);
var
@@ -185,7 +206,7 @@ begin
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
RIGHTS: Cardinal = {$IFNDEF UNIX}fmShareDenyWrite{$ELSE}%0100100100 {-r--r--r--}{$ENDIF};
begin
@@ -204,7 +225,8 @@ begin
end else
raise;
end;
AutoFlush:=true;
AutoFlush := true;
fAutoFree := aAutoFree;
end;

destructor TutlFileLogger.Destroy;
@@ -272,13 +294,16 @@ end;
procedure TutlLogger.RegisterConsumer(const aConsumer: IutlLogConsumer; const aFilter: TutlLogLevels);
var
ll: TutlLogLevel;
tmp: IutlLogConsumer;
begin
fConsumersLock.Acquire;
try
tmp := aConsumer; // HACK: store interface due to ref count bug :/
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
tmp := nil;
fConsumersLock.Release;
end;
if llDebug in aFilter then
@@ -291,7 +316,7 @@ var
begin
fConsumersLock.Acquire;
try
for ll:= low(ll) to high(ll) do
for ll := low(ll) to high(ll) do
if ll in aFilter then
fConsumers[ll].Remove(aConsumer);
finally


Зареждане…
Отказ
Запис