mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-05 13:38:31 +02:00
* Add EventFilter, use SafeFormat
This commit is contained in:
parent
105fae6d48
commit
d1a5ecd87e
@ -27,6 +27,10 @@ uses System.SysUtils,System.Classes;
|
||||
uses SysUtils,Classes;
|
||||
{$ENDIF FPC_DOTTEDUNITS}
|
||||
|
||||
const
|
||||
AllEvents = [Low(TEventType)..High(TEventType)];
|
||||
|
||||
|
||||
Type
|
||||
TEventLog = Class;
|
||||
TLogType = (ltSystem,ltFile,ltStdOut,ltStdErr);
|
||||
@ -53,6 +57,7 @@ Type
|
||||
FOnGetCustomEvent : TLogCodeEvent;
|
||||
FOnLogMessage: TLogMessageEvent;
|
||||
FPaused : Boolean;
|
||||
FEventFilter : TEventTypes;
|
||||
procedure SetActive(const Value: Boolean);
|
||||
procedure SetIdentification(const Value: String);
|
||||
procedure SetlogType(const Value: TLogType);
|
||||
@ -81,6 +86,7 @@ Type
|
||||
Function MapTypeToCategory(EventType : TEventType) : Word;
|
||||
Function MapTypeToEventID(EventType : TEventType) : DWord;
|
||||
Public
|
||||
Constructor Create(aOwner: TComponent); override;
|
||||
Destructor Destroy; override;
|
||||
Function EventTypeToString(E : TEventType) : String;
|
||||
Function RegisterMessageFile(AFileName : String) : Boolean; virtual;
|
||||
@ -102,6 +108,7 @@ Type
|
||||
Published
|
||||
Property AppendContent : Boolean Read fAppendContent Write fAppendContent;
|
||||
Property Identification : String Read FIdentification Write SetIdentification;
|
||||
Property EventFilter : TEventTypes Read FEventFilter Write FEventFilter default allevents;
|
||||
Property LogType : TLogType Read Flogtype Write SetlogType;
|
||||
Property Active : Boolean Read FActive write SetActive;
|
||||
Property RaiseExceptionOnError : Boolean Read FRaiseExceptionOnError Write FRaiseExceptionOnError;
|
||||
@ -141,6 +148,13 @@ implementation
|
||||
Resourcestring
|
||||
SErrOperationNotAllowed = 'Operation not allowed when eventlog is active.';
|
||||
|
||||
Constructor TEventLog.Create(aOwner: TComponent);
|
||||
|
||||
begin
|
||||
Inherited;
|
||||
FEventFilter:=AllEvents;
|
||||
end;
|
||||
|
||||
procedure TEventLog.CheckInactive;
|
||||
begin
|
||||
If Active then
|
||||
@ -205,13 +219,15 @@ end;
|
||||
procedure TEventLog.Log(EventType: TEventType; const Fmt: String;
|
||||
Args: array of const);
|
||||
begin
|
||||
Log(EventType,Format(Fmt,Args));
|
||||
Log(EventType,SafeFormat(Fmt,Args));
|
||||
end;
|
||||
|
||||
procedure TEventLog.Log(EventType: TEventType; const Msg: String);
|
||||
begin
|
||||
If Paused then
|
||||
exit;
|
||||
if not (EventType in EventFilter) then
|
||||
exit;
|
||||
EnsureActive;
|
||||
Case FlogType of
|
||||
ltFile : WriteFileLog(EventType,Msg);
|
||||
@ -231,7 +247,7 @@ begin
|
||||
FTimeStampFormat:='yyyy-mm-dd hh:nn:ss.zzz';
|
||||
TS:=FormatDateTime(FTimeStampFormat,Now);
|
||||
T:=EventTypeToString(EventType);
|
||||
Result:=Format('%s [%s %s] %s',[Identification,TS,T,Msg]);
|
||||
Result:=SafeFormat('%s [%s %s] %s',[Identification,TS,T,Msg]);
|
||||
end;
|
||||
|
||||
procedure TEventLog.WriteFileLog(EventType : TEventType; const Msg : String);
|
||||
@ -259,7 +275,7 @@ end;
|
||||
|
||||
procedure TEventLog.Log(const Fmt: String; Args: array of const);
|
||||
begin
|
||||
Log(Format(Fmt,Args));
|
||||
Log(SafeFormat(Fmt,Args));
|
||||
end;
|
||||
|
||||
procedure TEventLog.SetActive(const Value: Boolean);
|
||||
@ -353,7 +369,7 @@ end;
|
||||
|
||||
procedure TEventLog.Warning(const Fmt: String; Args: array of const);
|
||||
begin
|
||||
Warning(Format(Fmt,Args));
|
||||
Warning(SafeFormat(Fmt,Args));
|
||||
end;
|
||||
|
||||
procedure TEventLog.Warning(const Msg: String);
|
||||
@ -382,7 +398,7 @@ begin
|
||||
etWarning : Result:=SLogWarning;
|
||||
etError : Result:=SLogError;
|
||||
etDebug : Result:=SLogDebug;
|
||||
etCustom : Result:=Format(SLogCustom,[CustomLogType]);
|
||||
etCustom : Result:=SafeFormat(SLogCustom,[CustomLogType]);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user