source: branches/version-2_13-dev/data/class/pages/admin/system/LC_Page_Admin_System_Log.php @ 22926

Revision 22926, 5.5 KB checked in by Seasoft, 11 years ago (diff)

#2287 (環境によりデストラクタが正しく動作しないケースがある)
#2288 (リクエスト単位で実行されるべきログ出力がブロックにも適用されている)
#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

  • 不明確な仕様にコメントを残した。
  • 親デストラクタを呼ぶだけの記述は可読性が悪くなると考え削除した。(上述のチケットで OS の仕様に依存したデストラクタとなるため、敢えてアプリケーション側で記述しておく意義は薄れたという認識のもと。)
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
25
26/**
27 * ログ のページクラス.
28 *
29 * @package Page
30 * @author Seasoft 塚田将久
31 * @version $Id$
32 */
33class LC_Page_Admin_System_Log extends LC_Page_Admin_Ex
34{
35    var $arrLogList = array();
36
37    /**
38     * Page を初期化する.
39     *
40     * @return void
41     */
42    function init()
43    {
44        parent::init();
45        $this->tpl_mainpage = 'system/log.tpl';
46        $this->tpl_subno    = 'log';
47        $this->tpl_mainno   = 'system';
48        $this->tpl_maintitle = 'システム設定';
49        $this->tpl_subtitle = 'EC-CUBE ログ表示';
50        $this->line_max     = 50;
51    }
52
53    /**
54     * Page のプロセス.
55     *
56     * @return void
57     */
58    function process()
59    {
60        $this->action();
61        $this->sendResponse();
62    }
63
64    /**
65     * Page のアクション.
66     *
67     * @return void
68     */
69    function action()
70    {
71        $objFormParam = new SC_FormParam_Ex;
72
73        // パラメーター情報初期化
74        $this->lfInitParam($objFormParam);
75
76        // POST値をセット
77        $objFormParam->setParam($_REQUEST);
78        $this->arrErr = $objFormParam->checkError();
79        $this->arrForm = $objFormParam->getFormParamList();
80
81        $this->loadLogList();
82
83        if (empty($this->arrErr)) {
84            $this->line_max = $objFormParam->getValue('line_max');
85
86            $log_path = $this->getLogPath($objFormParam->getValue('log'));
87            $this->tpl_ec_log = $this->getEccubeLog($log_path);
88        }
89
90    }
91
92    /**
93     * パラメーターの初期化.
94     *
95     * @return void
96     */
97    function lfInitParam(&$objFormParam)
98    {
99        $objFormParam->addParam('ファイル', 'log', null, '', array());
100        $objFormParam->addParam('行数', 'line_max', INT_LEN, '', array('NUM_CHECK', 'MAX_LENGTH_CHECK'), 50);
101    }
102
103    /**
104     * EC-CUBE ログを取得する.
105     *
106     * @return array $arrLogs 取得したログ
107     */
108    function getEccubeLog($log_path_base)
109    {
110        $index = 0;
111        $arrLogs = array();
112        for ($gen = 0 ; $gen <= MAX_LOG_QUANTITY; $gen++) {
113            $path = $log_path_base;
114            if ($gen != 0) {
115                $path .= ".$gen";
116            }
117
118            // ファイルが存在しない場合、前世代のログへ
119            if (!file_exists($path)) continue;
120
121            $arrLogTmp = array_reverse(file($path));
122
123            $arrBodyReverse = array();
124            foreach ($arrLogTmp as $line) {
125                // 上限に達した場合、処理を抜ける
126                if (count($arrLogs) >= $this->line_max) break 2;
127
128                $line = chop($line);
129                if (preg_match('/^(\d+\/\d+\/\d+ \d+:\d+:\d+) \[([^\]]+)\] (.*)$/', $line, $arrMatch)) {
130                    $arrLogLine = array();
131                    // 日時
132                    $arrLogLine['date'] = $arrMatch[1];
133                    // パス
134                    $arrLogLine['path'] = $arrMatch[2];
135                    // 内容
136                    $arrBodyReverse[] = $arrMatch[3];
137                    $arrLogLine['body'] = implode("\n", array_reverse($arrBodyReverse));
138                    $arrBodyReverse = array();
139
140                    $arrLogs[] = $arrLogLine;
141                } else {
142                    // 内容
143                    $arrBodyReverse[] = $line;
144                }
145            }
146        }
147
148        return $arrLogs;
149    }
150
151    /**
152     * ログファイルのパスを取得する
153     *
154     * セキュリティ面をカバーする役割もある。
155     */
156    function getLogPath($log_name)
157    {
158        if (strlen($log_name) === 0) {
159            return LOG_REALFILE;
160        }
161        if (defined($const_name = $log_name . '_LOG_REALFILE')) {
162            return constant($const_name);
163        }
164        trigger_error('不正なログが指定されました。', E_USER_ERROR);
165    }
166
167    /**
168     * ログファイルの一覧を読み込む
169     *
170     * TODO mtb_constants から動的生成したい。
171     * @return void
172     */
173    function loadLogList()
174    {
175        $this->arrLogList[''] = '標準ログファイル';
176        $this->arrLogList['CUSTOMER'] = '会員ログイン ログファイル';
177        $this->arrLogList['ADMIN'] = '管理機能ログファイル';
178
179        if (defined('DEBUG_LOG_REALFILE') && strlen(DEBUG_LOG_REALFILE) >= 1) {
180            $this->arrLogList['DEBUG'] = 'デバッグログファイル';
181        }
182
183        if (defined('ERROR_LOG_REALFILE') && strlen(ERROR_LOG_REALFILE) >= 1) {
184            $this->arrLogList['ERROR'] = 'エラーログファイル';
185        }
186
187        if (defined('DB_LOG_REALFILE') && strlen(DB_LOG_REALFILE) >= 1) {
188            $this->arrLogList['DB'] = 'DBログファイル';
189        }
190    }
191}
Note: See TracBrowser for help on using the repository browser.