CRM-18095 cache the debugLogger to save some file_exists checks
authoreileen <emcnaughton@wikimedia.org>
Tue, 23 Feb 2016 23:58:06 +0000 (12:58 +1300)
committereileen <emcnaughton@wikimedia.org>
Wed, 24 Feb 2016 21:46:54 +0000 (10:46 +1300)
CRM/Core/Error.php

index 3c7e13186b067392d37972e73d77bfd728b61a27..cd146816da4918610ee2b5c05d829a5406bad56d 100644 (file)
@@ -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]);
   }
 
   /**