From cd6104ddb3e4ed60918e0f9dfdb99a271a19bc00 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Tue, 22 Oct 2019 15:08:41 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B02518=20If=20switching=20to=20log=20file?= =?UTF-8?q?=20rotation,=20rename=20setup/error=20legacy=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/config.class.inc.php | 7 +++++- core/log.class.inc.php | 46 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/core/config.class.inc.php b/core/config.class.inc.php index 7360d4348..7d7b61a0e 100644 --- a/core/config.class.inc.php +++ b/core/config.class.inc.php @@ -2000,7 +2000,12 @@ class Config fwrite($hFile, ");\n"); fwrite($hFile, '?'.'>'); // Avoid perturbing the syntax highlighting ! - return fclose($hFile); + $bReturn = fclose($hFile); + + MetaModel::LoadConfig($this); + FileLog::RenameLegacyLogFiles(); + + return $bReturn; } else { diff --git a/core/log.class.inc.php b/core/log.class.inc.php index c2db00c87..e16f03a7f 100644 --- a/core/log.class.inc.php +++ b/core/log.class.inc.php @@ -153,6 +153,52 @@ class FileLog $this->oFileNameBuilder = LogFileNameBuilderFactory::GetInstance($sFileName); } + /** + * Since 2.7.0 with the 'log_filename_builder_impl' param the logs will output to different files name + * As now by default iTop will use {@link WeeklyRotatingLogFileNameBuilder} (rotation each week), to avoid confusion, we're renaming + * the legacy error.log / setup.log. + * + * @since 2.7.0 N°2518 + * @uses utils::GetConfig() the config must be persisted ! + */ + public static function RenameLegacyLogFiles() + { + $oConfig = utils::GetConfig(); + IssueLog::Enable(APPROOT.'log/error.log'); // refresh log file used + $sLogFileNameParam = $oConfig->Get('log_filename_builder_impl'); + $aConfigValuesNoRotation = array('', 'DefaultLogFileNameBuilder'); + + $bIsLogRotationActivated = (!in_array($sLogFileNameParam, $aConfigValuesNoRotation, true)); + if (!$bIsLogRotationActivated) + { + return; + } + + IssueLog::Warning("Log name builder set to '$sLogFileNameParam', renaming legacy log files"); + $aLogFilesToRename = array( + 'log/setup.log' => 'log/setup.LEGACY.log', + 'log/error.log' => 'log/error.LEGACY.log', + ); + foreach ($aLogFilesToRename as $sLogCurrentName => $sLogNewName) + { + $sSource = APPROOT.$sLogCurrentName; + if (!file_exists($sSource)) + { + IssueLog::Info("Log file '$sLogCurrentName' does not exists, skipping"); + continue; + } + + $sDestination = APPROOT.$sLogNewName; + $bResult = rename($sSource, $sDestination); + if (!$bResult) + { + IssueLog::Error("Log file '$sLogCurrentName' cannot be renamed to '$sLogNewName'"); + continue; + } + IssueLog::Info("Log file '$sLogCurrentName' renamed to '$sLogNewName'"); + } + } + public function Error($sText) { $this->Write('Error | '.$sText);