/
class_error_handler.php
executable file
·132 lines (100 loc) · 3.61 KB
/
class_error_handler.php
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
<?php
/**
* Trellis Desk
*
* @copyright Copyright (C) 2009-2012 ACCORD5. All rights reserved.
* @license GNU General Public License version 3 or later; see LICENSE.txt
*/
class td_class_error_handler {
private static $log_path;
#=======================================
# @ Constructor
#=======================================
function __construct($debug=0)
{
define( 'TDEH_DEBUG', $debug );
set_error_handler( array( 'td_class_error_handler', 'error_handler' ) );
}
#=======================================
# @ Error Handler
#=======================================
public static function error_handler($errno, $errmsg, $errfile, $errline, $errcontext)
{
$process = false;
if ( $errno == E_WARNING || $errno == E_USER_ERROR || TDEH_DEBUG == 3 ) $process = true;
if ( ! $process )
{
if( TDEH_DEBUG == 1 )
{
if ( $errno == E_USER_WARNING ) $process = true;
}
elseif( TDEH_DEBUG == 2 )
{
if ( $errno == E_USER_WARNING || $errno == E_USER_NOTICE ) $process = true;
}
}
if ( error_reporting() == 0 ) $process = false;
if ( $process )
{
$log_msg = "[". gmdate( 'm/d/Y h:i:s P' ) ."] ";
switch( $errno )
{
case E_USER_ERROR:
echo "<strong>TD Fatal Error:</strong> ";
$log_msg .= "TD Fatal Error: ";
break;
case E_USER_WARNING:
echo "<strong>TD Warning:</strong> ";
$log_msg .= "TD Warning: ";
break;
case E_USER_NOTICE:
echo "<strong>TD Notice:</strong> ";
$log_msg .= "TD Notice: ";
break;
case E_WARNING:
echo "<strong>PHP Warning:</strong> ";
$log_msg .= "PHP Warning: ";
break;
case E_NOTICE:
echo "<strong>PHP Notice:</strong> ";
$log_msg .= "PHP Notice: ";
break;
case E_STRICT:
echo "<strong>PHP Strict:</strong> ";
$log_msg .= "PHP Strict: ";
break;
default:
echo "<strong>Unknown Error (". $errno ."):</strong> ";
$log_msg .= "Unknown Error (". $errno ."): ";
break;
}
echo $errmsg ." in <strong>". $errfile ."</strong> on line <strong>". $errline ."</strong>";
$log_msg .= $errmsg ." in '". $errfile ."' on line ". $errline ."\n";
echo "<br />\n";
ob_start();
debug_print_backtrace();
$trace = ob_get_contents();
ob_end_clean();
$trace = str_replace( '#', "\t#", $trace );
$log_msg .= $trace;
td_class_error_handler::log_error( $log_msg );
if ( $errno == E_USER_ERROR ) exit(1);
}
return true;
}
#=======================================
# @ Log Error
#=======================================
private function log_error($errmsg)
{
if ( td_class_error_handler::$log_path ) @error_log( $errmsg, 3, td_class_error_handler::$log_path );
}
#=======================================
# @ Set Log Path
#=======================================
public function set_log_path($path)
{
td_class_error_handler::$log_path = $path;
}
}
?>