[Svn-src-all:2748] [version-2_12-dev 21647] #1676 (ログファイルを分離する)

Seasoft admin @ mail.ec-cube.net
2012年 3月 14日 (水) 21:36:17 JST


Subversion committed to /home/svn/open 21647
http://svn.ec-cube.net/open_trac/changeset/21647
┌────────────────────────────┐
│更新者 :  Seasoft                                      │
│更新日時:  2012-03-14 21:36:17 +0900 (水, 14  3月 2012)│
└────────────────────────────┘

Log:
--------------------------------------------------------
#1676 (ログファイルを分離する)
  * 管理機能「システム設定>EC-CUBE ログ表示」画面

Changed:                      [U:修正,A:追加,D:削除]
--------------------------------------------------------
U   branches/version-2_12-dev/data/Smarty/templates/admin/system/log.tpl
U   branches/version-2_12-dev/data/class/pages/admin/system/LC_Page_Admin_System_Log.php

変更: branches/version-2_12-dev/data/Smarty/templates/admin/system/log.tpl
===================================================================
--- branches/version-2_12-dev/data/Smarty/templates/admin/system/log.tpl	2012-03-14 12:34:50 UTC (rev 21646)
+++ branches/version-2_12-dev/data/Smarty/templates/admin/system/log.tpl	2012-03-14 12:36:17 UTC (rev 21647)
@@ -22,7 +22,30 @@
  */
 *}-->
 
-<p>直近の<!--{$line_max}-->行</p>
+<style type="text/css">
+    th {
+        width: auto;
+    }
+</style>
+
+<!--{if count($arrErr) >= 1}-->
+    <div class="attention">
+        <!--{foreach from=$arrErr item=err}-->
+            <!--{$err}-->
+        <!--{/foreach}-->
+    </div>
+<!--{/if}-->
+
+<form action="?" name="form1" style="margin-bottom: 1ex;">
+    <!--{assign var=key value="log"}-->
+    <select name="<!--{$key|h}-->" style="<!--{$arrErr[$key]|sfGetErrorColor}-->">
+        <!--{html_options options=$arrLogList selected=$arrForm[$key]}-->
+    </select>
+    <!--{assign var=key value="line_max"}-->
+    直近の<input type="text" name="<!--{$key|h}-->" value="<!--{$arrForm[$key].value|h}-->" size="6" maxlength="<!--{$arrForm[$key].length|h}-->" style="<!--{$arrErr[$key]|sfGetErrorColor}-->" />行
+    <a class="btn-normal" href="javascript:;" onclick="form1.submit(); return false;"><span>読み込む</span></a>
+</form>
+
 <table class="list log">
     <tr>
         <th>日時</th>

変更: branches/version-2_12-dev/data/class/pages/admin/system/LC_Page_Admin_System_Log.php
===================================================================
--- branches/version-2_12-dev/data/class/pages/admin/system/LC_Page_Admin_System_Log.php	2012-03-14 12:34:50 UTC (rev 21646)
+++ branches/version-2_12-dev/data/class/pages/admin/system/LC_Page_Admin_System_Log.php	2012-03-14 12:36:17 UTC (rev 21647)
@@ -33,8 +33,7 @@
  */
 class LC_Page_Admin_System_Log extends LC_Page_Admin_Ex {
 
-    // }}}
-    // {{{ functions
+    var $arrLogList = array();
 
     /**
      * Page を初期化する.
@@ -77,14 +76,19 @@
         $this->lfInitParam($objFormParam);
 
         // POST値をセット
-        $objFormParam->setParam($_POST);
+        $objFormParam->setParam($_REQUEST);
+        $this->arrErr = $objFormParam->checkError();
+        $this->arrForm = $objFormParam->getFormParamList();
 
-        if (SC_Utils_Ex::sfIsInt($tmp = $objFormParam->getValue('line'))) {
-            $this->line_max = $tmp;
+        $this->loadLogList();
+
+        if (empty($this->arrErr)) {
+            $this->line_max = $objFormParam->getValue('line_max');
+
+            $log_path = $this->getLogPath($objFormParam->getValue('log'));
+            $this->tpl_ec_log = $this->getEccubeLog($log_path);
         }
 
-        $this->tpl_ec_log = $this->getEccubeLog();
-
         // フックポイント.
         $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance();
         $objPlugin->doAction('lc_page_admin_system_log_action_end', array($this));
@@ -102,11 +106,11 @@
     /**
      * パラメーターの初期化.
      *
-     * @return object SC_FormParam インスタンス
      * @return void
      */
     function lfInitParam(&$objFormParam) {
-        $objFormParam->addParam('line_max', 'line_max', INT_LEN, '', array('NUM_CHECK', 'MAX_LENGTH_CHECK', 'EXIST_CHECK'));
+        $objFormParam->addParam('ファイル', 'log', null, '', array());
+        $objFormParam->addParam('行数', 'line_max', INT_LEN, '', array('NUM_CHECK', 'MAX_LENGTH_CHECK'), 50);
     }
 
     /**
@@ -114,12 +118,12 @@
      *
      * @return array $arrLogs 取得したログ
      */
-    function getEccubeLog() {
+    function getEccubeLog($log_path_base) {
 
         $index = 0;
         $arrLogs = array();
         for ($gen = 0 ; $gen <= MAX_LOG_QUANTITY; $gen++) {
-            $path = LOG_REALFILE;
+            $path = $log_path_base;
             if ($gen != 0) {
                 $path .= ".$gen";
             }
@@ -131,6 +135,9 @@
 
             $arrBodyReverse = array();
             foreach ($arrLogTmp as $line) {
+                // 上限に達した場合、処理を抜ける
+                if (count($arrLogs) >= $this->line_max) break 2;
+
                 $line = chop($line);
                 if (preg_match('/^(\d+\/\d+\/\d+ \d+:\d+:\d+) \[([^\]]+)\] (.*)$/', $line, $arrMatch)) {
                     $arrLogLine = array();
@@ -144,9 +151,6 @@
                     $arrBodyReverse = array();
 
                     $arrLogs[] = $arrLogLine;
-
-                    // 上限に達した場合、処理を抜ける
-                    if (count($arrLogs) >= $this->line_max) break 2;
                 } else {
                     // 内容
                     $arrBodyReverse[] = $line;
@@ -155,4 +159,43 @@
         }
         return $arrLogs;
     }
+
+    /**
+     * ログファイルのパスを取得する
+     *
+     * セキュリティ面をカバーする役割もある。
+     */
+    function getLogPath($log_name) {
+        if (strlen($log_name) === 0) {
+            return LOG_REALFILE;
+        }
+        if (defined($const_name = $log_name . '_LOG_REALFILE')) {
+            return constant($const_name);
+        }
+        trigger_error('不正なログが指定されました。', E_USER_ERROR);
+    }
+
+    /**
+     * ログファイルの一覧を読み込む
+     *
+     * TODO mtb_constants から動的生成したい。
+     * @return void
+     */
+    function loadLogList() {
+        $this->arrLogList[''] = '標準ログファイル';
+        $this->arrLogList['CUSTOMER'] = '会員ログイン ログファイル';
+        $this->arrLogList['ADMIN'] = '管理機能ログファイル';
+
+        if (defined('DEBUG_LOG_REALFILE') && strlen(DEBUG_LOG_REALFILE) >= 1) {
+            $this->arrLogList['DEBUG'] = 'デバッグログファイル';
+        }
+
+        if (defined('ERROR_LOG_REALFILE') && strlen(ERROR_LOG_REALFILE) >= 1) {
+            $this->arrLogList['ERROR'] = 'エラーログファイル';
+        }
+
+        if (defined('DB_LOG_REALFILE') && strlen(DB_LOG_REALFILE) >= 1) {
+            $this->arrLogList['DB'] = 'DBログファイル';
+        }
+    }
 }




Svn-src-all メーリングリストの案内