From 69c6f18a1aa80f660f7e70f7defc0b9912a1e674 Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 25 Mar 2003 21:04:48 +0000 Subject: [PATCH] + Added support for custom log event type --- fcl/inc/eventlog.pp | 48 +++++++++++++++++++++++++++++++++++++----- fcl/os2/eventlog.inc | 17 +++++++++++++-- fcl/unix/eventlog.inc | 7 +++++- fcl/win32/eventlog.inc | 17 +++++++++++---- 4 files changed, 77 insertions(+), 12 deletions(-) diff --git a/fcl/inc/eventlog.pp b/fcl/inc/eventlog.pp index eb0eee42fb..756d1b8a90 100644 --- a/fcl/inc/eventlog.pp +++ b/fcl/inc/eventlog.pp @@ -23,9 +23,12 @@ interface uses SysUtils,Classes; Type + TEventLog = Class; TEventType = (etCustom,etInfo,etWarning,etError,etDebug); TLogType = (ltSystem,ltFile); - + TLogCodeEvent = Procedure (Sender : TObject; Var Code : DWord) of Object; + TLogCategoryEvent = Procedure (Sender : TObject; Var Code : Word) of Object; + TEventLog = Class(TComponent) Private FEventIDOffset : DWord; @@ -38,6 +41,9 @@ Type FFileName: String; FTimeStampFormat: String; FCustomLogType: Word; + FOnGetCustomCategory : TLogCategoryEvent; + FOnGetCustomEventID : TLogCodeEvent; + FOnGetCustomEvent : TLogCodeEvent; procedure SetActive(const Value: Boolean); procedure SetIdentification(const Value: String); procedure SetlogType(const Value: TLogType); @@ -52,16 +58,19 @@ Type procedure DeActivateFileLog; procedure DeActivateSystemLog; procedure CheckIdentification; - function MapTypeToEvent(EventType: TEventType): DWord; + Procedure DoGetCustomEventID(Var Code : DWord); + Procedure DoGetCustomEventCategory(Var Code : Word); + Procedure DoGetCustomEvent(Var Code : DWord); Protected Procedure CheckInactive; Procedure EnsureActive; + function MapTypeToEvent(EventType: TEventType): DWord; + Function MapTypeToCategory(EventType : TEventType) : Word; + Function MapTypeToEventID(EventType : TEventType) : DWord; Public Destructor Destroy; override; Function EventTypeToString(E : TEventType) : String; 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; Fmt : String; Args : Array of const); {$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 Info (Msg : String); {$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 LogType : TLogType Read Flogtype Write SetlogType; Property Active : Boolean Read FActive write SetActive; @@ -82,6 +92,9 @@ Type Property TimeStampFormat : String Read FTimeStampFormat Write FTimeStampFormat; Property CustomLogType : Word Read FCustomLogType Write FCustomLogType; 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; ELogError = Class(Exception); @@ -277,6 +290,28 @@ begin 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; begin Active:=False; @@ -287,7 +322,10 @@ end. { $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 } diff --git a/fcl/os2/eventlog.inc b/fcl/os2/eventlog.inc index a483c8752a..879bea10eb 100644 --- a/fcl/os2/eventlog.inc +++ b/fcl/os2/eventlog.inc @@ -232,23 +232,36 @@ end; function TEventLog.MapTypeToCategory(EventType: TEventType): Word; begin Result:=0; + If (EventType=ETCustom) then + DoGetCustomEventCategory(Result); end; function TEventLog.MapTypeToEventID(EventType: TEventType): DWord; begin Result:=0; + If (EventType=ETCustom) then + DoGetCustomEventID(Result); end; function TEventLog.MapTypeToEvent(EventType: TEventType): DWord; begin - Result := ord (EventType); + If EventType=etCustom Then + begin + Result:=CustomLogType; + DoGetCustomEvent(Result); + end + else + Result := ord (EventType); end; { $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 Revision 1.2 2003/03/02 02:01:35 hajny diff --git a/fcl/unix/eventlog.inc b/fcl/unix/eventlog.inc index 0c97d05daf..1631534fc7 100644 --- a/fcl/unix/eventlog.inc +++ b/fcl/unix/eventlog.inc @@ -99,12 +99,16 @@ end; function TEventLog.MapTypeToCategory(EventType: TEventType): Word; begin Result:=0; + If (EventType=ETCustom) then + DoGetCustomEventCategory(Result); end; function TEventLog.MapTypeToEventID(EventType: TEventType): DWord; begin Result:=0; + If (EventType=ETCustom) then + DoGetCustomEventID(Result); end; function TEventLog.MapTypeToEvent(EventType: TEventType): DWord; @@ -118,7 +122,8 @@ begin begin If CustomLogType=0 then CustomLogType:=LOG_NOTICE; - Result:=CustomLogType + Result:=CustomLogType; + DoGetCustomEvent(Result); end else Result:=WinET[EventType]; diff --git a/fcl/win32/eventlog.inc b/fcl/win32/eventlog.inc index fcc5a7d9b6..e35f885492 100644 --- a/fcl/win32/eventlog.inc +++ b/fcl/win32/eventlog.inc @@ -106,7 +106,10 @@ end; function TEventLog.MapTypeToCategory(EventType: TEventType): Word; begin - Result:=Ord(EventType); + If (EventType=ETCustom) then + DoGetCustomEventCategory(Result) + else + Result:=Ord(EventType); If Result=0 then Result:=1; end; @@ -114,9 +117,14 @@ end; function TEventLog.MapTypeToEventID(EventType: TEventType): DWord; begin - If (FEventIDOffset=0) then - FEventIDOffset:=1000; - Result:=FEventIDOffset+Ord(EventType); + If (EventType=ETCustom) then + DoGetCustomEventID(Result) + else + begin + If (FEventIDOffset=0) then + FEventIDOffset:=1000; + Result:=FEventIDOffset+Ord(EventType); + end; end; function TEventLog.MapTypeToEvent(EventType: TEventType): DWord; @@ -136,6 +144,7 @@ begin If CustomLogType=0 then CustomLogType:=EVENTLOG_SUCCESS; Result:=CustomLogType + DoGetCustomEvent(Result); end else Result:=WinET[EventType];