N°8260 - Change format of REST logs when they are close to the SQL field size limit

This commit is contained in:
jf-cbd
2025-03-13 15:39:00 +01:00
parent 29c75f626b
commit f5011bb200

View File

@@ -299,7 +299,12 @@ if (MetaModel::GetConfig()->Get('log_rest_service'))
$oLog->SetTrim('message', $sMessage);
$oLog->Set('code', $oResult->code);
$oResult->SanitizeContent();
$oLog->SetTrim('json_output', json_encode($oResult, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
$iUnescapeSlashAndUnicode = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
$sJsonOuputWithPrettyPrinting = json_encode($oResult, $iUnescapeSlashAndUnicode | JSON_PRETTY_PRINT);
$sJsonOutputWithoutPrettyPrinting = json_encode($oResult, $iUnescapeSlashAndUnicode);
!$oLog->StringFitsInField('json_output', $sJsonOuputWithPrettyPrinting) ?
$oLog->SetTrim('json_output', $sJsonOutputWithoutPrettyPrinting) : // too long, we don't make it pretty
$oLog->SetTrim('json_output', $sJsonOuputWithPrettyPrinting);
$oLog->DBInsertNoReload();
}