diff --git a/core/cmdbsource.class.inc.php b/core/cmdbsource.class.inc.php index e1b4a1d79..b82c665a0 100644 --- a/core/cmdbsource.class.inc.php +++ b/core/cmdbsource.class.inc.php @@ -761,7 +761,7 @@ class CMDBSource ); DeadLockLog::Info($sMessage, $iMySqlErrorNo, $aLogContext); - IssueLog::Error($sMessage, 'DeadLock', $e->getMessage()); + IssueLog::Error($sMessage, LogChannels::DEADLOCK, $e->getMessage()); } /** diff --git a/core/inlineimage.class.inc.php b/core/inlineimage.class.inc.php index 05b75ddc8..93aa6e11a 100644 --- a/core/inlineimage.class.inc.php +++ b/core/inlineimage.class.inc.php @@ -176,31 +176,29 @@ class InlineImage extends DBObject $sOQL = 'SELECT InlineImage WHERE temp_id = :temp_id'; $oSearch = DBObjectSearch::FromOQL($sOQL); $oSet = new DBObjectSet($oSearch, array(), array('temp_id' => $sTempId)); - $aInlineImagesId = array(); - while($oInlineImage = $oSet->Fetch()) - { - $aInlineImagesId[] = $oInlineImage->GetKey(); + $aInlineImagesId = array(); + while ($oInlineImage = $oSet->Fetch()) { + $aInlineImagesId[] = $oInlineImage->GetKey(); $oInlineImage->SetItem($oObject); $oInlineImage->Set('temp_id', ''); $oInlineImage->DBUpdate(); } - IssueLog::Trace('FinalizeInlineImages (see $aInlineImagesId for the id list)', 'InlineImage', array( - '$sObjectClass' => get_class($oObject), - '$sTransactionId' => $iTransactionId, - '$sTempId' => $sTempId, - '$aInlineImagesId' => $aInlineImagesId, - '$sUser' => UserRights::GetUser(), - 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], - )); + IssueLog::Trace('FinalizeInlineImages (see $aInlineImagesId for the id list)', LogChannels::INLINE_IMAGE, array( + '$sObjectClass' => get_class($oObject), + '$sTransactionId' => $iTransactionId, + '$sTempId' => $sTempId, + '$aInlineImagesId' => $aInlineImagesId, + '$sUser' => UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + )); } - else - { - IssueLog::Trace('FinalizeInlineImages "error" $iTransactionId is null', 'InlineImage', array( - '$sObjectClass' => get_class($oObject), - '$sTransactionId' => $iTransactionId, - '$sUser' => UserRights::GetUser(), - 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], - )); + else { + IssueLog::Trace('FinalizeInlineImages "error" $iTransactionId is null', LogChannels::INLINE_IMAGE, array( + '$sObjectClass' => get_class($oObject), + '$sTransactionId' => $iTransactionId, + '$sUser' => UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + )); } } @@ -220,12 +218,12 @@ class InlineImage extends DBObject $aInlineImagesId[] = $oInlineImage->GetKey(); $oInlineImage->DBDelete(); } - IssueLog::Trace('OnFormCancel', 'InlineImage', array( - '$sTempId' => $sTempId, - '$aInlineImagesId' => $aInlineImagesId, - '$sUser' => UserRights::GetUser(), - 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], - )); + IssueLog::Trace('OnFormCancel', LogChannels::INLINE_IMAGE, array( + '$sTempId' => $sTempId, + '$aInlineImagesId' => $aInlineImagesId, + '$sUser' => UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + )); } /** @@ -565,17 +563,17 @@ JS protected function AfterInsert() { - IssueLog::Trace(__METHOD__, 'InlineImage', array( - 'id' => $this->GetKey(), - 'expire' => $this->Get('expire'), - 'temp_id' => $this->Get('temp_id'), - 'item_class' => $this->Get('item_class'), - 'item_id' => $this->Get('item_id'), - 'item_org_id' => $this->Get('item_org_id'), - 'secret' => $this->Get('secret'), - 'user' => $sUser = UserRights::GetUser(), - 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], - 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], + IssueLog::Trace(__METHOD__, LogChannels::INLINE_IMAGE, array( + 'id' => $this->GetKey(), + 'expire' => $this->Get('expire'), + 'temp_id' => $this->Get('temp_id'), + 'item_class' => $this->Get('item_class'), + 'item_id' => $this->Get('item_id'), + 'item_org_id' => $this->Get('item_org_id'), + 'secret' => $this->Get('secret'), + 'user' => $sUser = UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], )); parent::AfterInsert(); @@ -583,17 +581,17 @@ JS protected function AfterUpdate() { - IssueLog::Trace(__METHOD__, 'InlineImage', array( - 'id' => $this->GetKey(), - 'expire' => $this->Get('expire'), - 'temp_id' => $this->Get('temp_id'), - 'item_class' => $this->Get('item_class'), - 'item_id' => $this->Get('item_id'), - 'item_org_id' => $this->Get('item_org_id'), - 'secret' => $this->Get('secret'), - 'user' => $sUser = UserRights::GetUser(), - 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], - 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], + IssueLog::Trace(__METHOD__, LogChannels::INLINE_IMAGE, array( + 'id' => $this->GetKey(), + 'expire' => $this->Get('expire'), + 'temp_id' => $this->Get('temp_id'), + 'item_class' => $this->Get('item_class'), + 'item_id' => $this->Get('item_id'), + 'item_org_id' => $this->Get('item_org_id'), + 'secret' => $this->Get('secret'), + 'user' => $sUser = UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], )); parent::AfterUpdate(); @@ -601,17 +599,17 @@ JS protected function AfterDelete() { - IssueLog::Trace(__METHOD__, 'InlineImage', array( - 'id' => $this->GetKey(), - 'expire' => $this->Get('expire'), - 'temp_id' => $this->Get('temp_id'), - 'item_class' => $this->Get('item_class'), - 'item_id' => $this->Get('item_id'), - 'item_org_id' => $this->Get('item_org_id'), - 'secret' => $this->Get('secret'), - 'user' => $sUser = UserRights::GetUser(), - 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], - 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], + IssueLog::Trace(__METHOD__, LogChannels::INLINE_IMAGE, array( + 'id' => $this->GetKey(), + 'expire' => $this->Get('expire'), + 'temp_id' => $this->Get('temp_id'), + 'item_class' => $this->Get('item_class'), + 'item_id' => $this->Get('item_id'), + 'item_org_id' => $this->Get('item_org_id'), + 'secret' => $this->Get('secret'), + 'user' => $sUser = UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], )); parent::AfterDelete(); diff --git a/core/log.class.inc.php b/core/log.class.inc.php index f4e7a10cf..39988557c 100644 --- a/core/log.class.inc.php +++ b/core/log.class.inc.php @@ -517,12 +517,9 @@ class FileLog { flock($hLogFile, LOCK_EX); $sDate = date('Y-m-d H:i:s'); - if (empty($aContext)) - { + if (empty($aContext)) { fwrite($hLogFile, "$sDate | $sText\n"); - } - else - { + } else { $sContext = var_export($aContext, true); fwrite($hLogFile, "$sDate | $sText\n$sContext\n"); } @@ -533,6 +530,21 @@ class FileLog } } + +/** + * Simple enum like class to factorize channels values as constants + * Channels are used especially as parameters in {@see \LogAPI} methods + * + * @since 2.7.5 3.0.0 N°4012 + */ +class LogChannels +{ + const DEADLOCK = 'DeadLock'; + const INLINE_IMAGE = 'InlineImage'; + const PORTAL = 'portal'; +} + + abstract class LogAPI { const CHANNEL_DEFAULT = ''; @@ -544,11 +556,11 @@ abstract class LogAPI const LEVEL_DEBUG = 'Debug'; const LEVEL_TRACE = 'Trace'; /** - * @var string default log level, can be overrided * @see GetMinLogLevel + * @var string default log level, can be overrided * @since 2.7.1 N°2977 */ - const LEVEL_DEFAULT = self::LEVEL_OK; + const LEVEL_DEFAULT = self::LEVEL_OK; protected static $aLevelsPriority = array( self::LEVEL_ERROR => 400, diff --git a/datamodels/2.x/itop-portal-base/portal/src/Controller/BrowseBrickController.php b/datamodels/2.x/itop-portal-base/portal/src/Controller/BrowseBrickController.php index c7776c65a..ed07b90fa 100644 --- a/datamodels/2.x/itop-portal-base/portal/src/Controller/BrowseBrickController.php +++ b/datamodels/2.x/itop-portal-base/portal/src/Controller/BrowseBrickController.php @@ -31,6 +31,7 @@ use DBObjectSet; use DBSearch; use FieldExpression; use IssueLog; +use LogChannels; use MetaModel; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; @@ -441,7 +442,7 @@ class BrowseBrickController extends BrickController } } - IssueLog::Debug('Portal BrowseBrick query', 'portal', array( + IssueLog::Debug('Portal BrowseBrick query', LogChannels::PORTAL, array( 'sPortalId' => $sPortalId, 'sBrickId' => $sBrickId, 'oql' => $oSet->GetFilter()->ToOQL(), diff --git a/datamodels/2.x/itop-portal-base/portal/src/Controller/ManageBrickController.php b/datamodels/2.x/itop-portal-base/portal/src/Controller/ManageBrickController.php index 7223abf49..58d19e62b 100644 --- a/datamodels/2.x/itop-portal-base/portal/src/Controller/ManageBrickController.php +++ b/datamodels/2.x/itop-portal-base/portal/src/Controller/ManageBrickController.php @@ -43,6 +43,7 @@ use FieldExpression; use iPopupMenuExtension; use IssueLog; use JSButtonItem; +use LogChannels; use MetaModel; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; @@ -814,7 +815,7 @@ class ManageBrickController extends BrickController ); } - IssueLog::Debug('Portal ManageBrick query', 'portal', array( + IssueLog::Debug('Portal ManageBrick query', LogChannels::PORTAL, array( 'sPortalId' => $sPortalId, 'sBrickId' => $sBrickId, 'sGroupingTab' => $sGroupingTab, diff --git a/pages/ajax.render.php b/pages/ajax.render.php index c19f8c12c..07aa82077 100644 --- a/pages/ajax.render.php +++ b/pages/ajax.render.php @@ -2646,15 +2646,15 @@ EOF $aResult['height'] = $aDimensions['height']; } - IssueLog::Trace('InlineImage created', 'InlineImage', array( - '$operation' => $operation, - '$aResult' => $aResult, - 'secret' => $oAttachment->Get('secret'), - 'temp_id' => $sTempId, - 'item_class' => $sObjClass, - 'user' => UserRights::GetUser(), - 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], - 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], + IssueLog::Trace('InlineImage created', LogChannels::INLINE_IMAGE, array( + '$operation' => $operation, + '$aResult' => $aResult, + 'secret' => $oAttachment->Get('secret'), + 'temp_id' => $sTempId, + 'item_class' => $sObjClass, + 'user' => UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], )); } else @@ -2697,15 +2697,15 @@ EOF $oAttachment->Set('secret', sprintf('%06x', mt_rand(0, 0xFFFFFF))); // something not easy to guess $iAttId = $oAttachment->DBInsert(); - IssueLog::Trace('InlineImage created', 'InlineImage', array( - '$operation' => $operation, - 'secret' => $oAttachment->Get('secret'), - 'temp_id' => $sTempId, - 'item_class' => $sObjClass, - 'user' => UserRights::GetUser(), - 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], - 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], - )); + IssueLog::Trace('InlineImage created', LogChannels::INLINE_IMAGE, array( + '$operation' => $operation, + 'secret' => $oAttachment->Get('secret'), + 'temp_id' => $sTempId, + 'item_class' => $sObjClass, + 'user' => UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], + )); } } catch (FileUploadException $e)