Skip to content

Commit

Permalink
Refactoring and correction
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosHe committed Dec 24, 2020
1 parent 8a0793e commit 8afd07d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
14 changes: 11 additions & 3 deletions samples/boss-lock.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{
"hash": "d41d8cd98f00b204e9800998ecf8427e",
"updated": "2020-12-24T12:33:51.3353566-03:00",
"updated": "2020-12-24T12:56:26.8645864-03:00",
"installedModules": {
"github.com/dliocode/horse-utils-clientip": {
"name": "horse-utils-clientip",
"version": "0.0.5",
"hash": "e70e774b0e0e7248d1e9028fc9c4542e",
"artifacts": {},
"failed": false,
"changed": false
},
"github.com/hashload/horse": {
"name": "horse",
"version": "v2.0.6",
Expand All @@ -12,8 +20,8 @@
},
"github.com/hashload/horse-logger": {
"name": "horse-logger",
"version": "0.1.5",
"hash": "0621e32582c643397c3b3c48aeffe33b",
"version": "1.0.1",
"hash": "327d195902f59abb5c093e2791c8d0b2",
"artifacts": {},
"failed": false,
"changed": false
Expand Down
2 changes: 1 addition & 1 deletion samples/boss.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"mainsrc": "./",
"projects": [],
"dependencies": {
"github.com/hashload/horse-logger": "^0.1.0"
"github.com/hashload/horse-logger": "^1.0.1"
}
}
2 changes: 1 addition & 1 deletion samples/samples.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<DCC_K>false</DCC_K>
<DCC_Namespace>System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace)</DCC_Namespace>
<SanitizedProjectName>samples</SanitizedProjectName>
<DCC_UnitSearchPath>modules\.dcp;modules\.dcu;modules;modules\horse\src;modules\horse-logger\src;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
<DCC_UnitSearchPath>modules\.dcp;modules\.dcu;modules;modules\horse\src;modules\horse-logger\src;modules\horse-utils-clientip\src;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Android)'!=''">
<DCC_UsePackage>DBXSqliteDriver;RESTComponents;DBXInterBaseDriver;emsclientfiredac;tethering;DataSnapFireDAC;PackageAspectKeyboard;bindcompfmx;fmx;FireDACIBDriver;FireDACDBXDriver;dbexpress;IndyCore;dsnap;emsclient;DataSnapCommon;FireDACCommon;RESTBackendComponents;soapserver;bindengine;CloudService;FireDACCommonDriver;DataSnapClient;inet;IndyIPCommon;bindcompdbx;IndyIPServer;IndySystem;fmxFireDAC;FireDAC;FireDACSqliteDriver;soaprtl;DbxCommonDriver;xmlrtl;soapmidas;DataSnapNativeClient;FireDACDSDriver;rtl;DbxClientDriver;CustomIPTransport;bindcomp;IndyIPClient;dbxcds;dsnapxml;DataSnapProviderClient;dbrtl;IndyProtocols;$(DCC_UsePackage)</DCC_UsePackage>
Expand Down
19 changes: 7 additions & 12 deletions src/Horse.Logger.pas
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ THorseLogger = class(TThread)
class function ValidateValue(AValue: Integer): string; overload;
class function ValidateValue(AValue: string): string; overload;
class function ValidateValue(AValue: TDateTime): string; overload;
class function BuildLogger: THorseCallback;
class function GetDefaultHorseLogger: THorseLogger;
public
procedure AfterConstruction; override;
Expand All @@ -47,12 +46,11 @@ THorseLogger = class(TThread)
class function GetDefault: THorseLogger;
class function New(AConfig: THorseLoggerConfig): THorseCallback; overload;
class function New: THorseCallback; overload;
class property HorseLoggerConfig : THorseLoggerConfig read FHorseLoggerConfig write FHorseLoggerConfig;
end;

const
DEFAULT_HORSE_LOG_FORMAT =
'${request_remote_addr} [${time}] ${request_user_agent}'+
'${request_clientip} [${time}] ${request_user_agent}'+
' "${request_method} ${request_path_info} ${request_version}"'+
' ${response_status} ${response_content_length}';

Expand Down Expand Up @@ -83,8 +81,8 @@ procedure Middleware(ARequest: THorseRequest; AResponse: THorseResponse; ANext:
LAfterDateTime := Now();
LMilliSecondsBetween := MilliSecondsBetween(LAfterDateTime, LBeforeDateTime);

LWebRequest := THorseHackRequest(ARequest).GetWebRequest;
LWebResponse := THorseHackResponse(AResponse).GetWebResponse;
LWebRequest := THorseHackRequest(ARequest).RawWebRequest;
LWebResponse := THorseHackResponse(AResponse).RawWebResponse;

LLog := THorseLogger.GetDefault.FHorseLoggerConfig.LogFormat;
LLog := LLog.Replace('${time}', THorseLogger.ValidateValue(LBeforeDateTime));
Expand Down Expand Up @@ -161,11 +159,6 @@ procedure THorseLogger.BeforeDestruction;
FreeInternalInstances;
end;

class function THorseLogger.BuildLogger: THorseCallback;
begin
Result := @Middleware;
end;

procedure THorseLogger.Execute;
var
LWait: TWaitResult;
Expand Down Expand Up @@ -227,7 +220,7 @@ procedure THorseLogger.FreeInternalInstances;
class function THorseLogger.New(AConfig: THorseLoggerConfig): THorseCallback;
begin
Self.FHorseLoggerConfig := AConfig;
Result := Middleware();
Result := Middleware;
end;

class function THorseLogger.New: THorseCallback;
Expand Down Expand Up @@ -283,6 +276,8 @@ procedure THorseLogger.SaveLogCache;

class destructor THorseLogger.UnInitialize;
begin
if Assigned(FHorseLoggerConfig) then
FreeAndNil(FHorseLoggerConfig);
if Assigned(FHorseLogger) then
begin
FHorseLogger.Terminate;
Expand All @@ -308,4 +303,4 @@ class function THorseLogger.ValidateValue(AValue: Integer): string;
Result := AValue.ToString;
end;

end.
end.

0 comments on commit 8afd07d

Please sign in to comment.