Skip to content

Commit

Permalink
Code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciussanchez committed May 3, 2022
1 parent 82d1708 commit 6eca169
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/Horse.Logger.Manager.pas
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,18 @@ THorseLoggerManagerClass = class of THorseLoggerManager;

THorseLoggerManager = class(THorseLoggerThread)
private
{ private declarations }
class var FProviderList: TList<IHorseLoggerProvider>;
class var FDefaultManager: THorseLoggerManager;
protected
{ protected declarations }
procedure DispatchLogCache; override;
class function GetProviderList: TList<IHorseLoggerProvider>;
class function ValidateValue(AValue: Integer): THorseLoggerLogItemNumber; overload;
class function ValidateValue(AValue: string): THorseLoggerLogItemString; overload;
// Incluido parametro AShort : Boolean - 2022-02-12
class function ValidateValue(AValue: TDateTime; AShort : Boolean): THorseLoggerLogItemString; overload;
class function ValidateValue(const AValue: Integer): THorseLoggerLogItemNumber; overload;
class function ValidateValue(const AValue: string): THorseLoggerLogItemString; overload;
class function ValidateValue(const AValue: TDateTime; const AShort: Boolean): THorseLoggerLogItemString; overload;
class function GetDefaultManager: THorseLoggerManager; static;
public
{ public declarations }
class function HorseCallback: THorseCallback; overload;
class function RegisterProvider(AProvider: IHorseLoggerProvider): THorseLoggerManagerClass;
class function RegisterProvider(const AProvider: IHorseLoggerProvider): THorseLoggerManagerClass;
class property DefaultManager: THorseLoggerManager read GetDefaultManager;
class destructor UnInitialize;
end;
Expand Down Expand Up @@ -67,10 +63,8 @@ procedure DefaultHorseCallback(AReq: THorseRequest; ARes: THorseResponse; ANext:
LMilliSecondsBetween := MilliSecondsBetween(LAfterDateTime, LBeforeDateTime);
LLog := THorseLoggerLog.Create;
try
// Incluido valor FALSE para parametro AShort - 2022-02-12
LLog.{$IFDEF FPC}Add{$ELSE}AddPair{$ENDIF}('time', THorseLoggerManager.ValidateValue(LBeforeDateTime, false));
// Incluido opcao 'time_short' - 2022-02-12
LLog.{$IFDEF FPC}Add{$ELSE}AddPair{$ENDIF}('time_short', THorseLoggerManager.ValidateValue(LBeforeDateTime, true));
LLog.{$IFDEF FPC}Add{$ELSE}AddPair{$ENDIF}('time', THorseLoggerManager.ValidateValue(LBeforeDateTime, False));
LLog.{$IFDEF FPC}Add{$ELSE}AddPair{$ENDIF}('time_short', THorseLoggerManager.ValidateValue(LBeforeDateTime, True));
LLog.{$IFDEF FPC}Add{$ELSE}AddPair{$ENDIF}('execution_time', THorseLoggerManager.ValidateValue(LMilliSecondsBetween.ToString));
LLog.{$IFDEF FPC}Add{$ELSE}AddPair{$ENDIF}('request_clientip', THorseLoggerManager.ValidateValue(ClientIP(AReq)));
LLog.{$IFDEF FPC}Add{$ELSE}AddPair{$ENDIF}('request_method', THorseLoggerManager.ValidateValue(AReq.RawWebRequest.Method));
Expand Down Expand Up @@ -161,7 +155,7 @@ class function THorseLoggerManager.HorseCallback: THorseCallback;
Result := DefaultHorseCallback;
end;

class function THorseLoggerManager.RegisterProvider(AProvider: IHorseLoggerProvider): THorseLoggerManagerClass;
class function THorseLoggerManager.RegisterProvider(const AProvider: IHorseLoggerProvider): THorseLoggerManagerClass;
begin
Result := THorseLoggerManager;
GetProviderList.Add(AProvider);
Expand All @@ -182,20 +176,20 @@ class function THorseLoggerManager.RegisterProvider(AProvider: IHorseLoggerProvi
end;
end;

class function THorseLoggerManager.ValidateValue(AValue: Integer): THorseLoggerLogItemNumber;
class function THorseLoggerManager.ValidateValue(const AValue: Integer): THorseLoggerLogItemNumber;
begin
Result := THorseLoggerLogItemNumber.Create(AValue);
end;

class function THorseLoggerManager.ValidateValue(AValue: string): THorseLoggerLogItemString;
class function THorseLoggerManager.ValidateValue(const AValue: string): THorseLoggerLogItemString;
begin
Result := THorseLoggerLogItemString.Create(AValue);
end;

class function THorseLoggerManager.ValidateValue(AValue: TDateTime; AShort : Boolean): THorseLoggerLogItemString;
class function THorseLoggerManager.ValidateValue(const AValue: TDateTime; const AShort: Boolean): THorseLoggerLogItemString;
begin
if (AShort) then
Result := THorseLoggerLogItemString.Create(FormatDateTime('dd/mm/yyyy hh:mm:ss.zzz', AValue))
if AShort then
Result := THorseLoggerLogItemString.Create(FormatDateTime('dd/mm/yyyy hh:mm:ss.zzz', AValue))
else
Result := THorseLoggerLogItemString.Create(FormatDateTime('dd/MMMM/yyyy hh:mm:ss.zzz', AValue));
end;
Expand Down

0 comments on commit 6eca169

Please sign in to comment.