+ Added support for custom log event type

This commit is contained in:
michael 2003-03-25 21:04:48 +00:00
parent 79d49a94bf
commit 69c6f18a1a
4 changed files with 77 additions and 12 deletions

View File

@ -23,8 +23,11 @@ interface
uses SysUtils,Classes; uses SysUtils,Classes;
Type Type
TEventLog = Class;
TEventType = (etCustom,etInfo,etWarning,etError,etDebug); TEventType = (etCustom,etInfo,etWarning,etError,etDebug);
TLogType = (ltSystem,ltFile); TLogType = (ltSystem,ltFile);
TLogCodeEvent = Procedure (Sender : TObject; Var Code : DWord) of Object;
TLogCategoryEvent = Procedure (Sender : TObject; Var Code : Word) of Object;
TEventLog = Class(TComponent) TEventLog = Class(TComponent)
Private Private
@ -38,6 +41,9 @@ Type
FFileName: String; FFileName: String;
FTimeStampFormat: String; FTimeStampFormat: String;
FCustomLogType: Word; FCustomLogType: Word;
FOnGetCustomCategory : TLogCategoryEvent;
FOnGetCustomEventID : TLogCodeEvent;
FOnGetCustomEvent : TLogCodeEvent;
procedure SetActive(const Value: Boolean); procedure SetActive(const Value: Boolean);
procedure SetIdentification(const Value: String); procedure SetIdentification(const Value: String);
procedure SetlogType(const Value: TLogType); procedure SetlogType(const Value: TLogType);
@ -52,16 +58,19 @@ Type
procedure DeActivateFileLog; procedure DeActivateFileLog;
procedure DeActivateSystemLog; procedure DeActivateSystemLog;
procedure CheckIdentification; procedure CheckIdentification;
function MapTypeToEvent(EventType: TEventType): DWord; Procedure DoGetCustomEventID(Var Code : DWord);
Procedure DoGetCustomEventCategory(Var Code : Word);
Procedure DoGetCustomEvent(Var Code : DWord);
Protected Protected
Procedure CheckInactive; Procedure CheckInactive;
Procedure EnsureActive; Procedure EnsureActive;
function MapTypeToEvent(EventType: TEventType): DWord;
Function MapTypeToCategory(EventType : TEventType) : Word;
Function MapTypeToEventID(EventType : TEventType) : DWord;
Public Public
Destructor Destroy; override; Destructor Destroy; override;
Function EventTypeToString(E : TEventType) : String; Function EventTypeToString(E : TEventType) : String;
Function RegisterMessageFile(AFileName : String) : Boolean; virtual; Function RegisterMessageFile(AFileName : String) : Boolean; virtual;
Function MapTypeToCategory(EventType : TEventType) : Word;
Function MapTypeToEventID(EventType : TEventType) : DWord;
Procedure Log (EventType : TEventType; Msg : String); {$ifndef fpc }Overload;{$endif} Procedure Log (EventType : TEventType; Msg : String); {$ifndef fpc }Overload;{$endif}
Procedure Log (EventType : TEventType; Fmt : String; Args : Array of const); {$ifndef fpc }Overload;{$endif} Procedure Log (EventType : TEventType; Fmt : String; Args : Array of const); {$ifndef fpc }Overload;{$endif}
Procedure Log (Msg : String); {$ifndef fpc }Overload;{$endif} Procedure Log (Msg : String); {$ifndef fpc }Overload;{$endif}
@ -74,6 +83,7 @@ Type
Procedure Debug (Fmt : String; Args : Array of const); {$ifndef fpc }Overload;{$endif} Procedure Debug (Fmt : String; Args : Array of const); {$ifndef fpc }Overload;{$endif}
Procedure Info (Msg : String); {$ifndef fpc }Overload;{$endif} Procedure Info (Msg : String); {$ifndef fpc }Overload;{$endif}
Procedure Info (Fmt : String; Args : Array of const); {$ifndef fpc }Overload;{$endif} Procedure Info (Fmt : String; Args : Array of const); {$ifndef fpc }Overload;{$endif}
Published
Property Identification : String Read FIdentification Write SetIdentification; Property Identification : String Read FIdentification Write SetIdentification;
Property LogType : TLogType Read Flogtype Write SetlogType; Property LogType : TLogType Read Flogtype Write SetlogType;
Property Active : Boolean Read FActive write SetActive; Property Active : Boolean Read FActive write SetActive;
@ -82,6 +92,9 @@ Type
Property TimeStampFormat : String Read FTimeStampFormat Write FTimeStampFormat; Property TimeStampFormat : String Read FTimeStampFormat Write FTimeStampFormat;
Property CustomLogType : Word Read FCustomLogType Write FCustomLogType; Property CustomLogType : Word Read FCustomLogType Write FCustomLogType;
Property EventIDOffset : DWord Read FEventIDOffset Write FEventIDOffset; Property EventIDOffset : DWord Read FEventIDOffset Write FEventIDOffset;
Property OnGetCustomCategory : TLogCategoryEvent Read FOnGetCustomCategory Write FOnGetCustomCategory;
Property OnGetCustomEventID : TLogCodeEvent Read FOnGetCustomEventID Write FOnGetCustomEventID;
Property OnGetCustomEvent : TLogCodeEvent Read FOnGetCustomEvent Write FOnGetCustomEvent;
End; End;
ELogError = Class(Exception); ELogError = Class(Exception);
@ -277,6 +290,28 @@ begin
end; end;
end; end;
Procedure TEventLog.DoGetCustomEventID(Var Code : DWord);
begin
If Assigned(FOnGetCustomEventID) then
FOnGetCustomEventID(Self,Code);
end;
Procedure TEventLog.DoGetCustomEventCategory(Var Code : Word);
begin
If Assigned(FOnGetCustomCategory) then
FOnGetCustomCategory(Self,Code);
end;
Procedure TEventLog.DoGetCustomEvent(Var Code : DWord);
begin
If Assigned(FOnGetCustomEvent) then
FOnGetCustomEvent(Self,Code);
end;
destructor TEventLog.Destroy; destructor TEventLog.Destroy;
begin begin
Active:=False; Active:=False;
@ -287,7 +322,10 @@ end.
{ {
$Log$ $Log$
Revision 1.1 2003-02-19 20:25:16 michael Revision 1.2 2003-03-25 21:04:48 michael
+ Added support for custom log event type
Revision 1.1 2003/02/19 20:25:16 michael
+ Added event log + Added event log
} }

View File

@ -232,23 +232,36 @@ end;
function TEventLog.MapTypeToCategory(EventType: TEventType): Word; function TEventLog.MapTypeToCategory(EventType: TEventType): Word;
begin begin
Result:=0; Result:=0;
If (EventType=ETCustom) then
DoGetCustomEventCategory(Result);
end; end;
function TEventLog.MapTypeToEventID(EventType: TEventType): DWord; function TEventLog.MapTypeToEventID(EventType: TEventType): DWord;
begin begin
Result:=0; Result:=0;
If (EventType=ETCustom) then
DoGetCustomEventID(Result);
end; end;
function TEventLog.MapTypeToEvent(EventType: TEventType): DWord; function TEventLog.MapTypeToEvent(EventType: TEventType): DWord;
begin begin
If EventType=etCustom Then
begin
Result:=CustomLogType;
DoGetCustomEvent(Result);
end
else
Result := ord (EventType); Result := ord (EventType);
end; end;
{ {
$Log$ $Log$
Revision 1.3 2003-03-20 20:15:27 hajny Revision 1.4 2003-03-25 21:08:10 michael
+ Added support for custom log event type
Revision 1.3 2003/03/20 20:15:27 hajny
* range checking has to be disabled * range checking has to be disabled
Revision 1.2 2003/03/02 02:01:35 hajny Revision 1.2 2003/03/02 02:01:35 hajny

View File

@ -99,12 +99,16 @@ end;
function TEventLog.MapTypeToCategory(EventType: TEventType): Word; function TEventLog.MapTypeToCategory(EventType: TEventType): Word;
begin begin
Result:=0; Result:=0;
If (EventType=ETCustom) then
DoGetCustomEventCategory(Result);
end; end;
function TEventLog.MapTypeToEventID(EventType: TEventType): DWord; function TEventLog.MapTypeToEventID(EventType: TEventType): DWord;
begin begin
Result:=0; Result:=0;
If (EventType=ETCustom) then
DoGetCustomEventID(Result);
end; end;
function TEventLog.MapTypeToEvent(EventType: TEventType): DWord; function TEventLog.MapTypeToEvent(EventType: TEventType): DWord;
@ -118,7 +122,8 @@ begin
begin begin
If CustomLogType=0 then If CustomLogType=0 then
CustomLogType:=LOG_NOTICE; CustomLogType:=LOG_NOTICE;
Result:=CustomLogType Result:=CustomLogType;
DoGetCustomEvent(Result);
end end
else else
Result:=WinET[EventType]; Result:=WinET[EventType];

View File

@ -106,6 +106,9 @@ end;
function TEventLog.MapTypeToCategory(EventType: TEventType): Word; function TEventLog.MapTypeToCategory(EventType: TEventType): Word;
begin begin
If (EventType=ETCustom) then
DoGetCustomEventCategory(Result)
else
Result:=Ord(EventType); Result:=Ord(EventType);
If Result=0 then If Result=0 then
Result:=1; Result:=1;
@ -114,9 +117,14 @@ end;
function TEventLog.MapTypeToEventID(EventType: TEventType): DWord; function TEventLog.MapTypeToEventID(EventType: TEventType): DWord;
begin begin
If (EventType=ETCustom) then
DoGetCustomEventID(Result)
else
begin
If (FEventIDOffset=0) then If (FEventIDOffset=0) then
FEventIDOffset:=1000; FEventIDOffset:=1000;
Result:=FEventIDOffset+Ord(EventType); Result:=FEventIDOffset+Ord(EventType);
end;
end; end;
function TEventLog.MapTypeToEvent(EventType: TEventType): DWord; function TEventLog.MapTypeToEvent(EventType: TEventType): DWord;
@ -136,6 +144,7 @@ begin
If CustomLogType=0 then If CustomLogType=0 then
CustomLogType:=EVENTLOG_SUCCESS; CustomLogType:=EVENTLOG_SUCCESS;
Result:=CustomLogType Result:=CustomLogType
DoGetCustomEvent(Result);
end end
else else
Result:=WinET[EventType]; Result:=WinET[EventType];