Browse Source

+ Added support for custom log event type

michael 22 years ago
parent
commit
69c6f18a1a
4 changed files with 77 additions and 12 deletions
  1. 43 5
      fcl/inc/eventlog.pp
  2. 15 2
      fcl/os2/eventlog.inc
  3. 6 1
      fcl/unix/eventlog.inc
  4. 13 4
      fcl/win32/eventlog.inc

+ 43 - 5
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
 
 }

+ 15 - 2
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

+ 6 - 1
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];

+ 13 - 4
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];