From 7c4fc37dd3cfb6f23bf2d04dd78dbd9518a71354 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Mon, 15 Feb 2016 14:28:57 +0900 Subject: [PATCH] Make debug log filename configurable --- classes/display/DisplayHandler.class.php | 13 ++++++++++--- common/defaults/config.php | 1 + common/framework/debug.php | 2 +- modules/admin/admin.admin.controller.php | 22 ++++++++++++++++++++++ modules/admin/admin.admin.view.php | 1 + modules/admin/lang/en.php | 5 ++++- modules/admin/lang/ko.php | 5 ++++- modules/admin/tpl/config_debug.html | 7 +++++++ 8 files changed, 50 insertions(+), 6 deletions(-) diff --git a/classes/display/DisplayHandler.class.php b/classes/display/DisplayHandler.class.php index 9cc22a001..bab8e6c67 100644 --- a/classes/display/DisplayHandler.class.php +++ b/classes/display/DisplayHandler.class.php @@ -209,8 +209,15 @@ class DisplayHandler extends Handler $content = ob_get_clean(); if ($display_type === 'file') { - $debug_file = RX_BASEDIR . 'files/debug/' . getInternalDateTime(RX_TIME, 'Ymd') . '.php'; - if (!file_exists($debug_file) || !filesize($debug_file)) + $log_filename = config('debug.log_filename') ?: 'files/debug/YYYYMMDD.php'; + $log_filename = str_replace(array('YYYY', 'YY', 'MM', 'DD'), array( + getInternalDateTime(RX_TIME, 'Y'), + getInternalDateTime(RX_TIME, 'y'), + getInternalDateTime(RX_TIME, 'm'), + getInternalDateTime(RX_TIME, 'd'), + ), $log_filename); + $log_filename = RX_BASEDIR . $log_filename; + if (!file_exists($log_filename) || !filesize($log_filename)) { $phpheader = '' . "\n"; } @@ -218,7 +225,7 @@ class DisplayHandler extends Handler { $phpheader = ''; } - FileHandler::writeFile($debug_file, $phpheader . $content, 'a'); + FileHandler::writeFile($log_filename, $phpheader . $content, 'a'); return ''; } else diff --git a/common/defaults/config.php b/common/defaults/config.php index 7fb040685..71ee5ff4f 100644 --- a/common/defaults/config.php +++ b/common/defaults/config.php @@ -92,6 +92,7 @@ return array( 'log_slow_queries' => 0, 'log_slow_triggers' => 0, 'log_slow_widgets' => 0, + 'log_filename' => null, 'display_type' => 'comment', 'display_to' => 'admin', 'allow' => array(), diff --git a/common/framework/debug.php b/common/framework/debug.php index 436645c80..b3e81dac6 100644 --- a/common/framework/debug.php +++ b/common/framework/debug.php @@ -408,7 +408,7 @@ class Debug { // Collect debug information. $data = (object)array( - 'timestamp' => DateTime::formatTimestampForCurrentUser('Y-m-d H:i:s P', RX_TIME), + 'timestamp' => DateTime::formatTimestamp('Y-m-d H:i:s', RX_TIME), 'url' => getCurrentPageUrl(), 'request' => (object)array( 'method' => $_SERVER['REQUEST_METHOD'] . ($_SERVER['REQUEST_METHOD'] !== \Context::getRequestMethod() ? (' (' . \Context::getRequestMethod() . ')') : ''), diff --git a/modules/admin/admin.admin.controller.php b/modules/admin/admin.admin.controller.php index 699ddbf23..4fe62512b 100644 --- a/modules/admin/admin.admin.controller.php +++ b/modules/admin/admin.admin.controller.php @@ -710,6 +710,28 @@ class adminAdminController extends admin Rhymix\Framework\Config::set('debug.display_type', strval($vars->debug_display_type) ?: 'comment'); Rhymix\Framework\Config::set('debug.display_to', strval($vars->debug_display_to) ?: 'admin'); + // Log filename + $log_filename = strval($vars->debug_log_filename); + $log_filename_today = str_replace(array('YYYY', 'YY', 'MM', 'DD'), array( + getInternalDateTime(RX_TIME, 'Y'), + getInternalDateTime(RX_TIME, 'y'), + getInternalDateTime(RX_TIME, 'm'), + getInternalDateTime(RX_TIME, 'd'), + ), $log_filename); + if (file_exists(RX_BASEDIR . $log_filename_today) && !is_writable(RX_BASEDIR . $log_filename_today)) + { + return new Object(-1, 'msg_debug_log_filename_not_writable'); + } + if (!file_exists(dirname(RX_BASEDIR . $log_filename)) && !FileHandler::makeDir(dirname(RX_BASEDIR . $log_filename))) + { + return new Object(-1, 'msg_debug_log_filename_not_writable'); + } + if (!is_writable(dirname(RX_BASEDIR . $log_filename))) + { + return new Object(-1, 'msg_debug_log_filename_not_writable'); + } + Rhymix\Framework\Config::set('debug.log_filename', $log_filename); + // IP access control $allowed_ip = array_map('trim', preg_split('/[\r\n]/', $vars->debug_allowed_ip)); $allowed_ip = array_unique(array_filter($allowed_ip, function($item) { diff --git a/modules/admin/admin.admin.view.php b/modules/admin/admin.admin.view.php index c3b9b7ba5..c31f8dd0c 100644 --- a/modules/admin/admin.admin.view.php +++ b/modules/admin/admin.admin.view.php @@ -496,6 +496,7 @@ class adminAdminView extends admin Context::set('debug_log_slow_queries', Rhymix\Framework\Config::get('debug.log_slow_queries')); Context::set('debug_log_slow_triggers', Rhymix\Framework\Config::get('debug.log_slow_triggers')); Context::set('debug_log_slow_widgets', Rhymix\Framework\Config::get('debug.log_slow_widgets')); + Context::set('debug_log_filename', Rhymix\Framework\Config::get('debug.log_filename') ?: 'files/debug/YYYYMMDD.php'); Context::set('debug_display_type', Rhymix\Framework\Config::get('debug.display_type')); Context::set('debug_display_to', Rhymix\Framework\Config::get('debug.display_to')); diff --git a/modules/admin/lang/en.php b/modules/admin/lang/en.php index 932f2c978..74b9d76f3 100644 --- a/modules/admin/lang/en.php +++ b/modules/admin/lang/en.php @@ -119,11 +119,14 @@ $lang->debug_seconds = 'seconds or longer'; $lang->debug_display_type = 'Display Debug Info As'; $lang->debug_display_type_comment = 'HTML source comment'; $lang->debug_display_type_panel = 'On-screen panel'; -$lang->debug_display_type_file = 'Write to file (files/debug)'; +$lang->debug_display_type_file = 'Write to file'; $lang->debug_display_to = 'Display Debug Info To'; $lang->debug_display_to_admin = 'Administrator only'; $lang->debug_display_to_ip = 'Visitors from IP adresses listed below'; $lang->debug_display_to_everyone = 'Everyone'; +$lang->debug_log_filename = 'Log filename'; +$lang->about_debug_log_filename = 'YYYYMMDD in the filename will be replaced with the current date.
It is recommended to split the log file by date to prevent it from getting too large.'; +$lang->msg_debug_log_filename_not_writable = 'Rhymix cannot write log files in the specified path.'; $lang->debug_allowed_ip = 'Allowed IP addresses'; $lang->autoinstall = 'EasyInstall'; $lang->last_week = 'Last Week'; diff --git a/modules/admin/lang/ko.php b/modules/admin/lang/ko.php index c8997181d..3e959816e 100644 --- a/modules/admin/lang/ko.php +++ b/modules/admin/lang/ko.php @@ -116,11 +116,14 @@ $lang->debug_seconds = '초 이상 소요시 기록'; $lang->debug_display_type = '디버그 정보 표시 방법'; $lang->debug_display_type_comment = 'HTML 소스에 표시 (주석)'; $lang->debug_display_type_panel = '화면에 표시 (패널)'; -$lang->debug_display_type_file = '파일에 기록 (files/debug)'; +$lang->debug_display_type_file = '파일에 기록'; $lang->debug_display_to = '디버그 정보 표시 대상'; $lang->debug_display_to_admin = '관리자에게만 표시'; $lang->debug_display_to_ip = '아래 IP의 방문자에게만 표시'; $lang->debug_display_to_everyone = '모두에게 표시'; +$lang->debug_log_filename = '디버그 정보 기록 파일'; +$lang->about_debug_log_filename = '파일명에 YYYYMMDD가 포함된 경우 날짜별로 파일을 분리하여 기록합니다.
파일을 분리하지 않으면 용량이 매우 커질 수 있으니 주의하십시오.'; +$lang->msg_debug_log_filename_not_writable = '지정한 경로에 로그 파일을 작성할 수 없습니다.'; $lang->debug_allowed_ip = '디버그 허용 IP'; $lang->autoinstall = '쉬운 설치'; $lang->last_week = '지난주'; diff --git a/modules/admin/tpl/config_debug.html b/modules/admin/tpl/config_debug.html index 861dadb78..06023192e 100644 --- a/modules/admin/tpl/config_debug.html +++ b/modules/admin/tpl/config_debug.html @@ -57,6 +57,13 @@ +
+ +
+ +

{$lang->about_debug_log_filename}

+
+