From 931ba0f3edeb246714772eb1fdb3e2c669a504c3 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 24 Feb 2016 12:58:06 +1300 Subject: [PATCH] CRM-18095 cache the debugLogger to save some file_exists checks --- CRM/Core/Error.php | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/CRM/Core/Error.php b/CRM/Core/Error.php index 3c7e13186b..cd146816da 100644 --- a/CRM/Core/Error.php +++ b/CRM/Core/Error.php @@ -634,31 +634,33 @@ class CRM_Core_Error extends PEAR_ErrorStack { * @return Log */ public static function createDebugLogger($comp = '') { - $config = CRM_Core_Config::singleton(); + if (!isset(\Civi::$statics[__CLASS__]['logger_file' . $comp])) { + $config = CRM_Core_Config::singleton(); - if ($comp) { - $comp = $comp . '.'; - } - - $fileName = "{$config->configAndLogDir}CiviCRM." . $comp . md5($config->dsn) . '.log'; - - // Roll log file monthly or if greater than 256M - // note that PHP file functions have a limit of 2G and hence - // the alternative was introduce - if (file_exists($fileName)) { - $fileTime = date("Ym", filemtime($fileName)); - $fileSize = filesize($fileName); - if (($fileTime < date('Ym')) || - ($fileSize > 256 * 1024 * 1024) || - ($fileSize < 0) - ) { - rename($fileName, - $fileName . '.' . date('YmdHi') - ); + if ($comp) { + $comp = $comp . '.'; } - } - return Log::singleton('file', $fileName); + $fileName = "{$config->configAndLogDir}CiviCRM." . $comp . md5($config->dsn) . '.log'; + + // Roll log file monthly or if greater than 256M + // note that PHP file functions have a limit of 2G and hence + // the alternative was introduce + if (file_exists($fileName)) { + $fileTime = date("Ym", filemtime($fileName)); + $fileSize = filesize($fileName); + if (($fileTime < date('Ym')) || + ($fileSize > 256 * 1024 * 1024) || + ($fileSize < 0) + ) { + rename($fileName, + $fileName . '.' . date('YmdHi') + ); + } + } + \Civi::$statics[__CLASS__]['logger_file' . $comp] = $fileName; + } + return Log::singleton('file', \Civi::$statics[__CLASS__]['logger_file' . $comp]); } /** -- 2.25.1