Skip to content

Commit

Permalink
Merge pull request #10 from andre-djsystem/Support-to-request_content…
Browse files Browse the repository at this point in the history
…-and-response_content

Add support to log request content and response content
  • Loading branch information
viniciussanchez authored Dec 30, 2021
2 parents bd62eba + 638c308 commit 568a644
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ src/*.~*
*.so
*.~*
*.a
*.stat
*.stat
*.bak
7 changes: 6 additions & 1 deletion src/Horse.Logger.Manager.pas
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface
uses

{$IFDEF FPC }
SysUtils, Classes, SyncObjs, Generics.Collections,
SysUtils, Classes, SyncObjs, Generics.Collections, fpjson,
{$ELSE}
System.SysUtils, System.JSON, System.SyncObjs, System.Classes, System.Generics.Collections,
{$ENDIF}
Expand Down Expand Up @@ -93,12 +93,17 @@ procedure DefaultHorseCallback(AReq: THorseRequest; ARes: THorseResponse; ANext:
LLog.{$IFDEF FPC}Add{$ELSE}AddPair{$ENDIF}('request_content_encoding', THorseLoggerManager.ValidateValue(AReq.RawWebRequest.ContentEncoding));
LLog.{$IFDEF FPC}Add{$ELSE}AddPair{$ENDIF}('request_content_type', THorseLoggerManager.ValidateValue(AReq.RawWebRequest.ContentType));
LLog.{$IFDEF FPC}Add{$ELSE}AddPair{$ENDIF}('request_content_length', THorseLoggerManager.ValidateValue(AReq.RawWebRequest.ContentLength.ToString));
LLog.{$IFDEF FPC}Add{$ELSE}AddPair{$ENDIF}('request_content', THorseLoggerManager.ValidateValue(AReq.RawWebRequest.Content));
LLog.{$IFDEF FPC}Add{$ELSE}AddPair{$ENDIF}('response_server', THorseLoggerManager.ValidateValue(ARes.RawWebResponse.Server));
LLog.{$IFDEF FPC}Add{$ELSE}AddPair{$ENDIF}('response_allow', THorseLoggerManager.ValidateValue(ARes.RawWebResponse.Allow));
LLog.{$IFDEF FPC}Add{$ELSE}AddPair{$ENDIF}('response_location', THorseLoggerManager.ValidateValue(ARes.RawWebResponse.Location));
LLog.{$IFDEF FPC}Add{$ELSE}AddPair{$ENDIF}('response_content_encoding', THorseLoggerManager.ValidateValue(ARes.RawWebResponse.ContentEncoding));
LLog.{$IFDEF FPC}Add{$ELSE}AddPair{$ENDIF}('response_content_type', THorseLoggerManager.ValidateValue(ARes.RawWebResponse.ContentType));
LLog.{$IFDEF FPC}Add{$ELSE}AddPair{$ENDIF}('response_content_length', THorseLoggerManager.ValidateValue(ARes.RawWebResponse.ContentLength.ToString));
if (not Assigned(ARes.Content)) or (not ARes.Content.InheritsFrom({$IF DEFINED(FPC)}TJsonData{$ELSE}TJSONValue{$ENDIF})) then
LLog.{$IFDEF FPC}Add{$ELSE}AddPair{$ENDIF}('response_content', THorseLoggerManager.ValidateValue(ARes.RawWebResponse.Content))
else
LLog.{$IFDEF FPC}Add{$ELSE}AddPair{$ENDIF}('response_content', THorseLoggerManager.ValidateValue({$IF DEFINED(FPC)}TJsonData(ARes.Content).AsJSON{$ELSE}TJSONValue(ARes.Content).ToJSON{$ENDIF}));
LLog.{$IFDEF FPC}Add{$ELSE}AddPair{$ENDIF}('response_status', THorseLoggerManager.ValidateValue(ARes.RawWebResponse.{$IF DEFINED(FPC)}Code.ToString(){$ELSE}StatusCode.ToString{$ENDIF}));
{$IF NOT DEFINED(FPC)}
LLog.AddPair('request_derived_from', THorseLoggerManager.ValidateValue(AReq.RawWebRequest.DerivedFrom));
Expand Down

0 comments on commit 568a644

Please sign in to comment.