[Legacy] Point all legacy install logs to logs/install.log

This commit is contained in:
Clemente Raposo 2025-01-14 13:02:49 +00:00 committed by c.raposo
parent 95e7acb164
commit daabfa9819
5 changed files with 212 additions and 15 deletions

View file

@ -121,6 +121,11 @@ class SugarLogger implements LoggerTemplate
* Reads the config file for logger settings
*/
public function __construct()
{
$this->init();
}
protected function init(): void
{
$config = SugarConfig::getInstance();
$this->ext = $config->get('logger.file.ext', $this->ext);

View file

@ -34,6 +34,8 @@ class AppInstallService
protected array $debug = [];
protected array $messages = [];
protected mixed $loggerBackup;
protected bool $loggerToggled = false;
public function runInstall(): array
{
@ -99,19 +101,20 @@ class AppInstallService
$GLOBALS['sql_queries'] = 0;
require_once('include/SugarLogger/LoggerManager.php');
require_once('sugar_version.php');
require_once('suitecrm_version.php');
require_once('install/install_utils.php');
require_once('install/install_defaults.php');
require_once('include/TimeDate.php');
require_once('include/Localization/Localization.php');
require_once('include/SugarTheme/SugarTheme.php');
require_once('include/utils/LogicHook.php');
require_once('data/SugarBean.php');
require_once('include/entryPoint.php');
require_once('jssource/minify.php'); // Do we need?
require_once('config.php');
require_once 'include/SugarLogger/LoggerManager.php';
require_once 'include/portability/Install/Logger/InstallLoggerManager.php';
require_once 'sugar_version.php';
require_once 'suitecrm_version.php';
require_once 'install/install_utils.php';
require_once 'install/install_defaults.php';
require_once 'include/TimeDate.php';
require_once 'include/Localization/Localization.php';
require_once 'include/SugarTheme/SugarTheme.php';
require_once 'include/utils/LogicHook.php';
require_once 'data/SugarBean.php';
require_once 'include/entryPoint.php';
require_once 'jssource/minify.php'; // Do we need?
require_once 'config.php';
if (!empty($sugar_config['installer_locked'])) {
@ -133,7 +136,7 @@ class AppInstallService
$locale = new Localization();
$GLOBALS['log'] = LoggerManager::getLogger();
$this->switchLogger();
$setup_sugar_version = $suitecrm_version;
@ -207,6 +210,7 @@ class AppInstallService
} catch (Exception $e) {
$this->addDebug($e->getMessage());
$this->addMessage($e->getMessage());
$this->switchLogger();
return $this->buildResult(false);
}
@ -230,6 +234,7 @@ class AppInstallService
if (!empty($validation_errors) && is_array($validation_errors)) {
$this->addMessage('DB configuration is not valid.');
$this->addDebugArray($validation_errors);
$this->switchLogger();
return $this->buildResult(false);
}
@ -237,6 +242,7 @@ class AppInstallService
if (!empty($validation_errors) && is_array($validation_errors)) {
$this->addMessage('Site configuration is not valid.');
$this->addDebugArray($validation_errors);
$this->switchLogger();
return $this->buildResult(false);
}
@ -244,6 +250,7 @@ class AppInstallService
if (!empty($validation_errors) && is_array($validation_errors)) {
$this->addMessage('Site configuration is not valid.');
$this->addDebugArray($validation_errors);
$this->switchLogger();
return $this->buildResult(false);
}
@ -255,6 +262,7 @@ class AppInstallService
if (!$result) {
$this->addDebug('Not able to write to /public/legacy/config.php');
$this->addMessage('Not able to write to /public/legacy/config.php');
$this->switchLogger();
return $this->buildResult(false);
}
@ -293,6 +301,7 @@ class AppInstallService
try {
$performSetupResult = $this->performSetup();
} catch (Exception $e) {
$this->switchLogger();
return $this->buildResult(false, [$e->getMessage()]);
}
@ -302,7 +311,7 @@ class AppInstallService
if (isset($performSetupResult['success']) && $performSetupResult['success'] === false) {
$success = false;
}
$this->switchLogger();
return $this->buildResult($success);
}
@ -1123,4 +1132,21 @@ class AppInstallService
}
/**
* @return void
*/
protected function switchLogger(): void
{
if ($this->loggerToggled === false) {
$this->loggerBackup = $GLOBALS['log'] ?? null;
$GLOBALS['log'] = InstallLoggerManager::getLogger();
$GLOBALS['install_log'] = &$GLOBALS['log'];
$this->loggerToggled = true;
return;
}
$GLOBALS['log'] = $this->loggerBackup;
$this->loggerToggled = false;
}
}

View file

@ -0,0 +1,52 @@
<?php
/**
* SuiteCRM is a customer relationship management program developed by SalesAgility Ltd.
* Copyright (C) 2025 SalesAgility Ltd.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SALESAGILITY, SALESAGILITY DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Supercharged by SuiteCRM" logo. If the display of the logos is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Supercharged by SuiteCRM".
*/
if (!defined('sugarEntry') || !sugarEntry) {
die('Not A Valid Entry Point');
}
require_once 'include/SugarLogger/SugarLogger.php';
class InstallLogger extends SugarLogger
{
protected function init(): void
{
$config = SugarConfig::getInstance();
$this->dateFormat = $config->get('logger.file.dateFormat', $this->dateFormat);
$this->maxLogs = $config->get('logger.file.maxLogs', $this->maxLogs);
$this->filesuffix = $config->get('logger.file.suffix', $this->filesuffix);
$this->defaultPerms = $config->get('logger.file.perms', $this->defaultPerms);
$this->logSize = '100MB';
$this->logfile = 'install';
$this->ext = '.log';
$log_dir = __DIR__ . '/../../../../../../logs';
$this->log_dir = $log_dir . (empty($log_dir) ? '' : '/');
unset($config);
$this->_doInitialization();
InstallLoggerManager::setLogger('default', 'InstallLogger');
}
}

View file

@ -0,0 +1,109 @@
<?php
/**
* SuiteCRM is a customer relationship management program developed by SalesAgility Ltd.
* Copyright (C) 2025 SalesAgility Ltd.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SALESAGILITY, SALESAGILITY DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Supercharged by SuiteCRM" logo. If the display of the logos is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Supercharged by SuiteCRM".
*/
if (!defined('sugarEntry') || !sugarEntry) {
die('Not A Valid Entry Point');
}
class InstallLoggerManager extends LoggerManager
{
/**
* This is the current log level
* @var string
*/
private static $_level = 'fatal';
/**
* This is the instance of the LoggerManager
* @var null|LoggerManager
*/
private static $_instance;
//these are the mappings for levels to different log types
private static $_logMapping = [
'default' => 'InstallLogger',
];
// These are the log level mappings anything with a lower value than your current log level will be logged
private static $_levelMapping = [
'debug' => 100,
'info' => 70,
'warn' => 50,
'deprecated' => 40,
'error' => 25,
'fatal' => 10,
'security' => 5,
'off' => 0,
];
//only let the getLogger instantiate this object
private function __construct()
{
$this->setLevel('info');
if (empty(self::$_loggers)) {
$this->_findAvailableLoggers();
}
}
/**
* Returns a logger instance
* @return LoggerManager
*/
public static function getLogger()
{
if (!self::$_instance) {
self::$_instance = new InstallLoggerManager();
}
return self::$_instance;
}
protected function _findAvailableLoggers()
{
foreach (['include/portability/Install/Logger', 'custom/include/portability/Install/Logger'] as $location) {
if (is_dir($location) && $dir = opendir($location)) {
while (($file = readdir($dir)) !== false) {
if ($file === '..'
|| $file === '.'
|| $file === 'LoggerTemplate.php'
|| $file === 'LoggerManager.php'
|| !is_file("$location/$file")
) {
continue;
}
require_once("$location/$file");
$loggerClass = basename($file, '.php');
if (class_exists($loggerClass) && class_implements($loggerClass, 'LoggerTemplate')) {
self::$_loggers[$loggerClass] = new $loggerClass();
}
}
}
}
}
}

View file

@ -769,6 +769,11 @@ function handleLog4Php()
function installLog($entry)
{
if (!empty($GLOBALS['install_log'])) {
$GLOBALS['install_log']->info($entry);
return;
}
global $mod_strings;
$nl = '
'.gmdate("Y-m-d H:i:s").'...';