diff --git a/core/log.class.inc.php b/core/log.class.inc.php index df92d2ae0..e3f03d7b5 100644 --- a/core/log.class.inc.php +++ b/core/log.class.inc.php @@ -1157,6 +1157,14 @@ class ExceptionLog extends LogAPI $aContext['exception class'] = get_class($oException); } + if (empty($aContext['file'])) { + $aContext['file'] = $oException->getFile(); + } + + if (empty($aContext['line'])) { + $aContext['line'] =$oException->getLine(); + } + self::Log($sLevel, $oException->getMessage(), get_class($oException), $aContext); } diff --git a/datamodels/2.x/itop-portal-base/portal/src/EventListener/ExceptionListener.php b/datamodels/2.x/itop-portal-base/portal/src/EventListener/ExceptionListener.php index ac9da8a3a..2ea5543e0 100644 --- a/datamodels/2.x/itop-portal-base/portal/src/EventListener/ExceptionListener.php +++ b/datamodels/2.x/itop-portal-base/portal/src/EventListener/ExceptionListener.php @@ -88,8 +88,6 @@ class ExceptionListener implements ContainerAwareInterface // Log exception in iTop log \ExceptionLog::LogException($oException, [ 'uri' => $oEvent->getRequest()->getUri(), - 'file' => $oException->getFile(), - 'line' => $oException->getLine(), ]); // Prepare data for template diff --git a/test/core/Log/ExceptionLogTest.php b/test/core/Log/ExceptionLogTest.php index fb6c943ac..a91d5e942 100644 --- a/test/core/Log/ExceptionLogTest.php +++ b/test/core/Log/ExceptionLogTest.php @@ -72,10 +72,13 @@ class ExceptionLogTest extends ItopDataTestCase $aContext = ['contextKey1' => 'value']; foreach ($aLevels as $i => $sLevel) { - $oException = new $aExceptions[$i]("Iteration number $i"); + + $sExpectedFile=__FILE__; + $oException = new $aExceptions[$i]("Iteration number $i"); $sExpectedLine = __LINE__; //Both should remain on the same line + $iExpectedWriteNumber = $aExpectedWriteNumber[$i]; $iExpectedDbWriteNumber = $aExpectedDbWriteNumber[$i]; - $aExpectedFileContext = array_merge($aContext, ['exception class' => get_class($oException)]); //The context is preserved, and, if the key 'exception class' is not yet in the array, it is added + $aExpectedFileContext = array_merge($aContext, ['exception class' => get_class($oException), 'file' => $sExpectedFile, 'line' => $sExpectedLine]); //The context is preserved, and, if the key 'exception class' is not yet in the array, it is added $mockFileLog->expects($this->exactly($iExpectedWriteNumber)) ->method($sLevel) ->with($oException->GetMessage(), $sChannel, $aExpectedFileContext)