forked from netcommons/NetCommons2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger_ViewDisplayManage.class.php
More file actions
367 lines (339 loc) · 8.95 KB
/
Logger_ViewDisplayManage.class.php
File metadata and controls
367 lines (339 loc) · 8.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<?php
//
// Authors: Ryuji Masukawa
//
// $Id: Logger_ViewDisplayManage.class.php,v 1.13 2008/07/07 05:20:34 Ryuji.M Exp $
//
/**
* ファイルに出力するLogger
*
* @author Ryuji Masukawa
**/
class Logger_ViewDisplayManage extends Logger {
var $_instance;
function Logger_ViewDisplayManage() {
$this->_instance =& Logger_ViewDisplay::getInstance();
}
/**
* fatalレベル以上のログを出力
*
* @param string $message エラーメッセージ
* @access public
**/
function sql_trace($message, $caller = null) {
$this->_instance->output(LEVEL_SQL, $message, $caller);
}
/**
* fatalレベル以上のログを出力
*
* @param string $message エラーメッセージ
* @access public
**/
function fatal($message, $caller = null) {
$this->_instance->output(LEVEL_FATAL, $message, $caller);
}
/**
* errorレベル以上のログを出力
*
* @param string $message エラーメッセージ
* @access public
**/
function error($message, $caller = null) {
$this->_instance->output(LEVEL_ERROR, $message, $caller);
}
/**
* warnレベル以上のログを出力
*
* @param string $message エラーメッセージ
* @access public
**/
function warn($message, $caller = null) {
$this->_instance->output(LEVEL_WARN, $message, $caller);
}
/**
* infoレベル以上のログを出力
*
* @param string $message エラーメッセージ
* @access public
**/
function info($message, $caller = null) {
$this->_instance->output(LEVEL_INFO, $message, $caller);
}
/**
* debugレベル以上のログを出力
*
* @param string $message エラーメッセージ
* @access public
**/
function debug($message, $caller = null) {
$this->_instance->output(LEVEL_DEBUG, $message, $caller);
}
/**
* traceレベル以上のログを出力
*
* @param string $message エラーメッセージ
* @access public
**/
function trace($message, $caller = null) {
$this->_instance->output(LEVEL_TRACE, $message, $caller);
}
}
class Logger_ViewDisplay {
/**
* エラーリスト
*
* @var array
* @access private
*/
var $_errors = array();
//var $_container = null;
/**
* fatal error (E_USER_ERROR=256)
*
* @var boolean
* @access private
*/
var $_isFatal = false;
/**
* コンストラクター
*
* @access private
*/
function Logger_ViewDisplay() {
set_error_handler("setErrorHandle");
register_shutdown_function("redisterShutdown");
//$this->_container =& DIContainerFactory::getContainer();
}
/**
* Logger_ViewDisplayクラスの唯一のインスタンスを返却
*
* @return ObjectLogger_ViewDisplayクラスのインスタンス
* @access public
**/
function &getInstance($set_instance = null) {
static $instance = null;
if ($instance === NULL) {
$instance = new Logger_ViewDisplay();
}
return $instance;
}
/**
* デバッグログ用のエラーハンドラ関数
* Note:デバッグログでのfile名は、パスなし errLineなし
* @access private
*/
function setLoggerHandle($errNo, $errStr, $errFile, $errLine=NULL)
{
$container =& DIContainerFactory::getContainer();
$write_flag = false;
if($errNo != LEVEL_SQL) {
if (defined("PHP_DEBUG")) {
if(PHP_DEBUG)
$php_debug = 1;
else
$php_debug = 0;
if (defined("TRACE_LOG_LEVEL")) {
$trace_log_level = TRACE_LOG_LEVEL;
} else {
$trace_log_level = LEVEL_TRACE;
}
} else {
//if($this->_container)
$session =& $container->getComponent("Session");
if(is_object($session)) {
$php_debug = $session->getParameter("_php_debug");
$trace_log_level = $session->getParameter("_trace_log_level");
} else {
$php_debug = 0;
$trace_log_level = LEVEL_TRACE;
}
}
if($php_debug) {
if ($trace_log_level <= $errNo) {
$write_flag = true;
}
}
} else {
//SQLデバッグ
if (defined("SQL_DEBUG")) {
if(SQL_DEBUG)
$sql_debug = 1;
else
$sql_debug = 0;
} else {
$session =& $container->getComponent("Session");
if(is_object($session)) {
$sql_debug = $session->getParameter("_sql_debug");
} else {
$sql_debug = 0;
}
}
if($sql_debug) {
$actionChain =& $container->getComponent("ActionChain");
$action_name = $actionChain->getCurActionName();
$pathList = explode("_", $action_name);
if(!(count($pathList) > 1 && $pathList[0] == "common" && $pathList[1] == "download")) {
$write_flag = true;
}
}
}
if($write_flag) {
$new_error = array(
'errno' => $errNo,
'errstr' => $errStr,
'errfile' => $errFile,
'errline' => $errLine
);
$this->_errors[] = $new_error;
}
}
/**
* エラー文字列描画処理
* NOTE: LEVEL_XXXと定義済の定数が同じにならないように配慮すること
* @access private
*/
function renderErrors()
{
$output = '';
if ($this->_isFatal) {
$output .= 'This page cannot be displayed due to an internal error.<br/><br/>';
}
if (empty($this->_errors)) {
return $output;
}
foreach( $this->_errors as $error )
{
$output .="<div class=\"logger";
switch ( $error['errno'] )
{
case E_USER_NOTICE:
$output .=" logger_notice\">";
$output .= "[User_Notice]: ";
break;
case E_USER_WARNING:
$output .=" logger_warning\">";
$output .= "[User_Warning]: ";
break;
case E_USER_ERROR:
$output .=" logger_error\">";
$output .= "[User_Error]: ";
break;
case E_NOTICE:
$output .=" logger_notice\">";
$output .= "[PHP_Notice]: ";
break;
case E_WARNING:
$output .=" logger_warning\">";
$output .= "[PHP_Warning]: ";
break;
case LEVEL_FATAL:
$output .=" logger_fatal\">";
$output .= "[LOG_FATAL]: ";
break;
case LEVEL_ERROR:
$output .=" logger_error\">";
$output .= "[LOG_ERROR]: ";
break;
case LEVEL_WARN:
$output .=" logger_warning\">";
$output .= "[LOG_WARN]: ";
break;
case LEVEL_INFO:
$output .=" logger_notice\">";
$output .= "[LOG_INFO]: ";
break;
case LEVEL_DEBUG:
$output .=" logger_debug\">";
$output .= "[LOG_DEBUG]: ";
break;
case LEVEL_TRACE:
$output .=" logger_trace\">";
$output .= "[LOG_TRACE]: ";
break;
case LEVEL_SQL:
$output .=" logger_sql\">";
$output .= "[SQL]: ";
break;
default:
$output .=" logger_other\">";
$output .= "[Unknown_Condition_" . $error['errno'] . "]: ";
}
if($error['errline'] != NULL)
$output .= sprintf( "%s in file %s line %s<br />\n", htmlspecialchars($error['errstr'], ENT_QUOTES), $error['errfile'], $error['errline'] );
else {
if($error['errfile'] != NULL)
$output .= sprintf( "%s in file %s<br />\n", htmlspecialchars($error['errstr'], ENT_QUOTES), $error['errfile'] );
else
$output .= sprintf( "%s<br />\n", $error['errstr']);
}
$output .="</div>";
}
if($output != "")
$output = "<div class=\"logger_block\">\n".$output."\n</div>";
//$output = "<hr />\n".$output;
return $output;
}
/**
* ログを出力する関数
*
* @param integer $logLevel ログレベル
* @param string $message エラーメッセージ
* @param mixed $caller 呼び出し元
* @access public
* @since 3.0.0
**/
function output($logLevel, $message, $caller) {
Logger_ViewDisplay::setLoggerHandle($logLevel, $message, $caller);
}
/**
* エラーハンドル
*
* @param array エラー情報の配列
* @access public
* @return void
*/
function handleError($error)
{
if (($error['errno'] & error_reporting()) != $error['errno']) {
return;
}
$this->_errors[] = $error;
if ($error['errno'] == E_USER_ERROR) {
$this->_isFatal = true;
exit();
}
}
}
/**
* ユーザ定義のエラーハンドラ関数
*
* @access public
*/
function setErrorHandle($errNo, $errStr, $errFile, $errLine) {
$new_error = array(
'errno' => $errNo,
'errstr' => $errStr,
'errfile' => preg_replace("|^" . urlencode(BASE_DIR) . "/|", '', $errFile),
'errline' => $errLine
);
$error_handler =& Logger_ViewDisplay::getInstance();
$error_handler->handleError($new_error);
}
/**
* シャットダウン時に実行する関数
*
* @access public
*/
function redisterShutdown() {
$container =& DIContainerFactory::getContainer();
$request =& $container->getComponent("Request");
if($request) {
$action_name = $request->getParameter(ACTION_KEY);
//TODO:ヘッダー出力ではログを出力不可 後に削除するかも
if(!preg_match("/^headerinc/", $action_name)){
$error_handler =& Logger_ViewDisplay::getInstance();
echo $error_handler->renderErrors();
}
}
}
?>