From f278ae5e7566580428fa7e6d2bdad9d1157f02a5 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Wed, 30 May 2018 20:48:04 +0900 Subject: [PATCH] Add methods to enable/disable Debug log collection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 크론탭 등에서 다수의 쿼리를 실행하거나 각종 일괄처리 작업을 할 때 디버그 기록 때문에 메모리 사용량이 무한정 증가하는 문제 방지 --- common/framework/debug.php | 61 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/common/framework/debug.php b/common/framework/debug.php index 112816994..04836b6b5 100644 --- a/common/framework/debug.php +++ b/common/framework/debug.php @@ -10,6 +10,7 @@ class Debug /** * Store log entries here. */ + protected static $_enabled = true; protected static $_aliases = array(); protected static $_entries = array(); protected static $_errors = array(); @@ -22,6 +23,26 @@ class Debug protected static $_remote_requests = array(); protected static $_slow_remote_requests = array(); + /** + * Enable log collection. + * + * @return void + */ + public static function enable() + { + self::$_enabled = true; + } + + /** + * Disable log collection. + * + * @return void + */ + public static function disable() + { + self::$_enabled = false; + } + /** * Get all entries. * @@ -225,6 +246,12 @@ class Debug */ public static function addEntry($message) { + // Do not store log if disabled. + if (!self::$_enabled) + { + return; + } + // Get the backtrace. $backtrace = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS); if (count($backtrace) > 1 && $backtrace[1]['function'] === 'debugPrint' && !$backtrace[1]['class']) @@ -264,6 +291,12 @@ class Debug */ public static function addError($errno, $errstr, $errfile, $errline, $errcontext) { + // Do not store log if disabled. + if (!self::$_enabled) + { + return; + } + // Do not handle error types that we were told to ignore. if (!($errno & error_reporting())) { @@ -307,6 +340,13 @@ class Debug */ public static function addQuery($query) { + // Do not store log if disabled. + if (!self::$_enabled) + { + return; + } + + // Prepare the log entry. $query_object = (object)array( 'type' => 'Query', 'time' => microtime(true), @@ -359,6 +399,13 @@ class Debug */ public static function addTrigger($trigger) { + // Do not store log if disabled. + if (!self::$_enabled) + { + return; + } + + // Prepare the log entry. $trigger_object = (object)array( 'type' => 'Trigger', 'time' => microtime(true), @@ -386,6 +433,13 @@ class Debug */ public static function addWidget($widget) { + // Do not store log if disabled. + if (!self::$_enabled) + { + return; + } + + // Prepare the log entry. $widget_object = (object)array( 'type' => 'Widget', 'time' => microtime(true), @@ -411,6 +465,13 @@ class Debug */ public static function addRemoteRequest($request) { + // Do not store log if disabled. + if (!self::$_enabled) + { + return; + } + + // Prepare the log entry. $request_object = (object)array( 'type' => 'Remote Request', 'time' => microtime(true),