2014-05-18 18:09:07 +00:00
|
|
|
unit X2Log.Intf;
|
|
|
|
|
|
|
|
interface
|
|
|
|
uses
|
2014-05-30 12:51:01 +00:00
|
|
|
System.Classes,
|
2014-05-18 18:09:07 +00:00
|
|
|
System.SysUtils;
|
|
|
|
|
2014-05-30 12:51:01 +00:00
|
|
|
|
2014-05-18 18:09:07 +00:00
|
|
|
type
|
|
|
|
TX2LogLevel = (Verbose, Info, Warning, Error);
|
2014-05-31 20:47:52 +00:00
|
|
|
TX2LogLevels = set of TX2LogLevel;
|
2014-05-18 18:09:07 +00:00
|
|
|
|
|
|
|
|
2014-05-26 17:20:27 +00:00
|
|
|
const
|
|
|
|
X2LogLevelsAll = [Low(TX2LogLevel)..High(TX2LogLevel)];
|
|
|
|
X2LogLevelsDefault = X2LogLevelsAll - [Verbose];
|
|
|
|
|
|
|
|
|
|
|
|
type
|
2014-05-30 12:51:01 +00:00
|
|
|
{ Details }
|
|
|
|
IX2LogDetails = interface
|
|
|
|
['{86F24F52-CE1F-4A79-936F-A5805D84E18A}']
|
2014-05-31 20:10:10 +00:00
|
|
|
function GetSerializerIID: TGUID;
|
|
|
|
|
|
|
|
property SerializerIID: TGUID read GetSerializerIID;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
IX2LogDetailsSerializer = interface
|
|
|
|
['{E75F6F4E-A671-4622-878C-F59C64FB1320}']
|
|
|
|
procedure Serialize(ADetails: IX2LogDetails; AStream: TStream);
|
|
|
|
function Deserialize(AStream: TStream): IX2LogDetails;
|
2014-05-30 12:51:01 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
IX2LogDetailsCopyable = interface
|
|
|
|
['{BA93B3CD-4F05-4887-A585-78093E0B31C9}']
|
|
|
|
procedure CopyToClipboard;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
IX2LogDetailsStreamable = interface
|
|
|
|
['{7DD0756D-F06E-4267-A433-04BEFF4FA955}']
|
|
|
|
procedure SaveToStream(AStream: TStream);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ Logging }
|
2014-05-25 14:20:58 +00:00
|
|
|
IX2LogBase = interface
|
2014-05-18 18:09:07 +00:00
|
|
|
['{1949E8DC-6DC5-43DC-B678-55CF8274E79D}']
|
2014-10-20 12:07:44 +00:00
|
|
|
procedure Log(ALevel: TX2LogLevel; const AMessage: string; const ACategory: string = ''; ADetails: IX2LogDetails = nil); overload;
|
|
|
|
procedure Log(ALevel: TX2LogLevel; ADateTime: TDateTime; const AMessage: string; const ACategory: string = ''; ADetails: IX2LogDetails = nil); overload;
|
2014-05-18 18:09:07 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-05-25 14:20:58 +00:00
|
|
|
IX2LogObserver = interface(IX2LogBase)
|
2014-05-18 18:09:07 +00:00
|
|
|
['{CBC5C18E-84EE-43F4-8DBE-C66D06FCDE74}']
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2017-04-26 15:20:48 +00:00
|
|
|
TX2LogExceptionDetailsProc = reference to procedure(const AKey, AValue: string);
|
|
|
|
|
2014-05-18 18:09:07 +00:00
|
|
|
IX2LogExceptionStrategy = interface
|
|
|
|
['{C0B7950E-BE0A-4A21-A7C5-F8322FD4E205}']
|
2017-04-26 15:20:48 +00:00
|
|
|
procedure Execute(AException: Exception; out AMessage: string; AAddDetails: TX2LogExceptionDetailsProc);
|
2014-05-18 18:09:07 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-05-25 14:20:58 +00:00
|
|
|
IX2LogObservable = interface(IX2LogBase)
|
|
|
|
['{50B47D5D-11E4-40E0-BBC4-8BA70697C1F9}']
|
2014-05-18 18:09:07 +00:00
|
|
|
procedure Attach(AObserver: IX2LogObserver);
|
|
|
|
procedure Detach(AObserver: IX2LogObserver);
|
2014-05-25 14:20:58 +00:00
|
|
|
end;
|
|
|
|
|
2014-05-18 18:09:07 +00:00
|
|
|
|
2014-05-25 14:20:58 +00:00
|
|
|
IX2Log = interface(IX2LogObservable)
|
|
|
|
['{A6FF38F9-EDA8-4C76-9C95-2C0317560D78}']
|
2014-05-18 18:09:07 +00:00
|
|
|
procedure SetExceptionStrategy(AStrategy: IX2LogExceptionStrategy);
|
|
|
|
|
2014-10-20 12:07:44 +00:00
|
|
|
function Category(const ACategory: string): IX2Log;
|
|
|
|
|
2014-05-18 18:09:07 +00:00
|
|
|
procedure Verbose(const AMessage: string; const ADetails: string = '');
|
2014-05-30 12:51:01 +00:00
|
|
|
procedure VerboseEx(const AMessage: string; ADetails: IX2LogDetails = nil);
|
2016-10-10 20:17:53 +00:00
|
|
|
procedure VerboseS(const AMessage: string; ANamedParams: array of const); overload;
|
2014-05-30 12:51:01 +00:00
|
|
|
|
2014-05-18 18:09:07 +00:00
|
|
|
procedure Info(const AMessage: string; const ADetails: string = '');
|
2014-05-30 12:51:01 +00:00
|
|
|
procedure InfoEx(const AMessage: string; ADetails: IX2LogDetails = nil);
|
2016-10-10 20:17:53 +00:00
|
|
|
procedure InfoS(const AMessage: string; ANamedParams: array of const); overload;
|
2014-05-30 12:51:01 +00:00
|
|
|
|
2014-05-18 18:09:07 +00:00
|
|
|
procedure Warning(const AMessage: string; const ADetails: string = '');
|
2014-05-30 12:51:01 +00:00
|
|
|
procedure WarningEx(const AMessage: string; ADetails: IX2LogDetails = nil);
|
2016-10-10 20:17:53 +00:00
|
|
|
procedure WarningS(const AMessage: string; ANamedParams: array of const); overload;
|
2014-05-30 12:51:01 +00:00
|
|
|
|
2014-05-18 18:09:07 +00:00
|
|
|
procedure Error(const AMessage: string; const ADetails: string = '');
|
2014-05-30 12:51:01 +00:00
|
|
|
procedure ErrorEx(const AMessage: string; ADetails: IX2LogDetails = nil);
|
2016-10-10 20:17:53 +00:00
|
|
|
procedure ErrorS(const AMessage: string; ANamedParams: array of const); overload;
|
2014-05-30 12:51:01 +00:00
|
|
|
|
|
|
|
procedure Exception(AException: Exception; const AMessage: string = '');
|
2014-10-20 13:38:28 +00:00
|
|
|
procedure ExceptionEx(AException: Exception; const AMessage: string = ''; const ACategory: string = '');
|
2017-04-26 15:20:48 +00:00
|
|
|
procedure ExceptionS(AException: Exception; const AMessage: string; ANamedParams: array of const);
|
2014-05-18 18:09:07 +00:00
|
|
|
end;
|
2014-05-25 14:20:58 +00:00
|
|
|
|
|
|
|
|
2016-10-15 07:17:33 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
IX2LogDateTime = interface
|
|
|
|
['{F0E6196B-C7E7-46C9-8764-D457AB957534}']
|
|
|
|
function GetValue: TDateTime;
|
|
|
|
|
|
|
|
property Value: TDateTime read GetValue;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ Use this wrapper when passing a TDateTime to one of the structured logging
|
|
|
|
methods, otherwise Delphi will pass it as a floating point value. }
|
2016-10-15 07:37:58 +00:00
|
|
|
function LogDT: IX2LogDateTime; overload;
|
|
|
|
function LogDT(AValue: TDateTime): IX2LogDateTime; overload;
|
2016-10-15 07:17:33 +00:00
|
|
|
|
|
|
|
|
2014-05-18 18:09:07 +00:00
|
|
|
implementation
|
2016-10-15 07:17:33 +00:00
|
|
|
type
|
|
|
|
TX2LogDateTime = class(TInterfacedObject, IX2LogDateTime)
|
|
|
|
private
|
|
|
|
FValue: TDateTime;
|
|
|
|
public
|
|
|
|
constructor Create(AValue: TDateTime);
|
|
|
|
|
|
|
|
function GetValue: TDateTime;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-10-15 07:37:58 +00:00
|
|
|
function LogDT: IX2LogDateTime;
|
|
|
|
begin
|
|
|
|
Result := LogDT(Now);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function LogDT(AValue: TDateTime): IX2LogDateTime;
|
2016-10-15 07:17:33 +00:00
|
|
|
begin
|
|
|
|
Result := TX2LogDateTime.Create(AValue);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TX2LogDateTime }
|
|
|
|
constructor TX2LogDateTime.Create(AValue: TDateTime);
|
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
|
|
|
|
FValue := AValue;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2LogDateTime.GetValue: TDateTime;
|
|
|
|
begin
|
|
|
|
Result := FValue;
|
|
|
|
end;
|
2014-05-18 18:09:07 +00:00
|
|
|
|
|
|
|
end.
|