XPressME Integration Kit

Trac

source: trunk/xpressme_integration_kit/include/xpress_debug_log.php @ 352

Last change on this file since 352 was 352, checked in by toemon, 15 years ago

予約投稿、xmlrpc 投稿時のイベント通知問題の修正 fixes #194
イベント通知のデバッグ用の処理追加

File size: 4.7 KB
Line 
1<?php
2
3// define('XPRESS_EVENT_DEBUG',1);
4
5if (!function_exists('xpress_debug')) {
6        function xpress_debug($title = '',$ditail_show = false)
7        {
8                $module_dirpath = dirname(dirname(__FILE__));
9                $root_path = dirname(dirname(dirname(dirname(__FILE__))));
10                $_debug_file = $module_dirpath . '/wp-content/xpress_debug.log';
11                $_fp = fopen($_debug_file, 'a');
12                $stamp = date("Y/m/d G:i:s" , time());
13                $backtraces = array_reverse(debug_backtrace());
14                fwrite($_fp, "\n*********************************************************************************************************\n");
15                fwrite($_fp, $title . '(' . $stamp . ")\n");
16                fwrite($_fp, '$_SERVER[]' . "\n");     
17                $srerver = "\t" . str_replace("\n","\n\t",sprint_r($_SERVER));
18                fwrite($_fp, $srerver . "\n\n");
19
20                fwrite($_fp, "BACK TRACE" . "\n");     
21                foreach($backtraces as $backtrace){
22                $trace = $backtrace['file']. "\tLINE(" . $backtrace['line'] . ")\t" . $backtrace['function']  . "()\n";
23                $trace = str_replace($root_path,"",$trace);
24                $trace = str_replace("\\","/",$trace);
25                $trace = str_replace($root_path,"",$trace);
26                $trace = "\t" . $trace;
27
28                $trace_ditail = "\t" . str_replace("\n","\n\t\t",sprint_r($backtrace));
29                if ($ditail_show)
30                        fwrite($_fp, $trace . $trace_ditail . "\n");
31                else
32                        fwrite($_fp, $trace . "\n");
33                }
34                fclose($_fp);
35        }
36}
37
38if (!function_exists('xpress_debug_message')) {
39        function xpress_debug_message($message = '')
40        {
41                $module_dirpath = dirname(dirname(__FILE__));
42                $root_path = dirname(dirname(dirname(dirname(__FILE__))));
43                $_debug_file = $module_dirpath . '/wp-content/xpress_debug.log';
44                $_fp = fopen($_debug_file, 'a');
45                $stamp = date("Y/m/d G:i:s" , time());
46                fwrite($_fp, "\n*********************************************************************************************************\n");
47                fwrite($_fp, '(' . $stamp . ")\n");
48                fwrite($_fp, $message . "\n"); 
49                fclose($_fp);
50        }
51}
52
53if (!function_exists('sprint_r')) {
54    function sprint_r($var) {
55             ob_start();
56             print_r($var);
57             $ret = ob_get_contents();
58             ob_end_clean();
59      return $ret;
60    }
61}
62
63function xpress_error_handler($errno,$errstr,$errfile,$errline,$errcontext) {
64        $module_dirpath = dirname(dirname(__FILE__));
65        $root_path = dirname(dirname(dirname(dirname(__FILE__))));
66       
67        $show_backtrace = true;
68
69        // Time stamp of error entry
70        $dt = date("Y-m-d H:i:s (T)");
71
72        // define an assoc array of error string
73        // in reality the only entries we should
74        // consider are E_WARNING, E_NOTICE, E_USER_ERROR,
75        // E_USER_WARNING and E_USER_NOTICE
76        $errortype = array (
77                E_ERROR          => "Error",
78                E_WARNING        => "Warning",
79                E_PARSE          => "Parsing Error",
80                E_NOTICE          => "Notice",
81                E_CORE_ERROR      => "Core Error",
82                E_CORE_WARNING    => "Core Warning",
83                E_COMPILE_ERROR  => "Compile Error",
84                E_COMPILE_WARNING => "Compile Warning",
85                E_USER_ERROR      => "User Error",
86                E_USER_WARNING    => "User Warning",
87                E_USER_NOTICE    => "User Notice",
88                E_STRICT          => "Runtime Notice"
89        );
90        if (strstr($errstr, 'Use of undefined constant xpress_debug_message - assumed') !== false) return;
91        // set of errors for which a var trace will be saved
92        $user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE);
93
94        $err = "<errorentry>\n";
95        $err .= "\t<datetime>" . $dt . "</datetime>\n";
96        $err .= "\t<errornum>" . $errno . "</errornum>\n";
97        $err .= "\t<errortype>" . $errortype[$errno] . "</errortype>\n";
98        $err .= "\t<errormsg>" . $errstr . "</errormsg>\n";
99        $err .= "\t<scriptname>" . $errfile . "</scriptname>\n";
100        $err .= "\t<scriptlinenum>" . $errline . "</scriptlinenum>\n";
101        $err .= "\t<errcontext>" . $errcontext . "</errcontext>\n";
102
103        if (in_array($errno, $user_errors)) {
104                $err .= "\t<vartrace>" . wddx_serialize_value($vars, "Variables") . "</vartrace>\n";
105        }
106        $err .= "</errorentry>\n\n";
107
108        $err_trace = '';
109        if ($show_backtrace){   
110                $backtraces = array_reverse(debug_backtrace());
111                $err_trace .= "BACK TRACE\n";
112                foreach($backtraces as $backtrace){
113                        $trace = @$backtrace['file']. "\tLINE(" . @$backtrace['line'] . ")\t" . @$backtrace['function']  . "()\n";
114                        $trace = str_replace($root_path,"",$trace);
115                        $trace = str_replace("\\","/",$trace);
116                        $trace = str_replace($root_path,"",$trace);
117                        $trace = "\t" . $trace;
118                        $err_trace .= $trace;
119                }
120        }
121        $head = "\n***** XPressME ERROR LOG ****************************************************************************************************\n";
122        $message = $head . $err . $err_trace;
123        $_debug_file = $module_dirpath . '/wp-content/xpress_error.log';
124        if ($errno != E_STRICT) {
125                $_fp = fopen($_debug_file, 'a');
126                fwrite($_fp, $message);
127                fclose($_fp);
128        }
129}
130?>
Note: See TracBrowser for help on using the repository browser.