@@ -45,42 +45,26 @@ public function writeLog(ParsedResponse $parsedResponse): void
4545 $ this ->maskSensitiveMemberPII = (bool )$ this ->paramsProvider ->getLogParameterValue ('mask_sensitive_member_pii ' );
4646 }
4747
48- $ requestStringParts = [];
49- $ requestOptions = $ WSRequest ->getOptions ();
50- foreach (['query ' , 'json ' , 'body ' ] as $ field ) {
51- if (!empty ($ requestOptions [$ field ])) {
52- $ value = $ requestOptions [$ field ];
53- if ($ field === 'body ' && !empty ($ value ['body ' ])) {
54- $ value = $ value ['body ' ];
55- }
56- try {
57- $ requestStringParts [] = is_string ($ value )
58- ? $ value
59- : json_encode ($ value , JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR );
60- } catch (\JsonException $ e ) {
61- $ requestStringParts [] = $ e ->getMessage ();
62- }
63- }
64- }
65- $ requestString = implode ("\n\n" , $ requestStringParts );
66-
67- $ responseBody = $ parsedResponse ->responseBody ;
48+ $ requestString = $ WSRequest ->getLogString ();
49+ $ responseString = $ parsedResponse ->getLogString (
50+ (bool )$ this ->paramsProvider ->getLogParameterValue ('log_response_headers ' )
51+ );
6852 if ($ this ->maskSensitiveData ) {
6953 MaskLogHelper::maskSensitiveVar ($ requestString , $ this ->maskSensitiveMemberPII );
70- MaskLogHelper::maskSensitiveVar ($ responseBody , true );
54+ MaskLogHelper::maskSensitiveVar ($ responseString , true );
7155 }
7256 $ responseMaxLength = $ this ->paramsProvider ->getLogParameterValue ('max_length ' , 900000 );
73- if ($ responseBody && strlen ($ responseBody ) > $ responseMaxLength ) {
74- $ response = substr ($ responseBody , 0 , $ responseMaxLength );
75- $ responseBody = $ response ;
57+ if ($ responseString && strlen ($ responseString ) > $ responseMaxLength ) {
58+ $ response = substr ($ responseString , 0 , $ responseMaxLength );
59+ $ responseString = $ response ;
7660 }
7761
7862 $ logContext = [
7963 'service ' => $ webservice ,
8064 'action ' => $ WSRequest ->getCustomAction (),
8165 'clientip ' => $ currentRequest ?->getClientIp(),
8266 'request ' => $ requestString ,
83- 'response ' => $ responseBody ,
67+ 'response ' => $ responseString ,
8468 'error ' => $ parsedResponse ->exception ?->getMessage(),
8569 'duration ' => $ parsedResponse ->mainAsyncResponse ->WSResponse ->getInfo ('total_time ' ),
8670 'uri ' => $ WSRequest ->action ,
0 commit comments