Index: trunk/php/wmerrors/wmerrors.c |
— | — | @@ -50,11 +50,13 @@ |
51 | 51 | PHP_INI_BEGIN() |
52 | 52 | STD_PHP_INI_BOOLEAN("wmerrors.enabled", "0", PHP_INI_ALL, OnUpdateBool, enabled, zend_wmerrors_globals, wmerrors_globals ) |
53 | 53 | STD_PHP_INI_ENTRY("wmerrors.message_file", "", PHP_INI_ALL, OnUpdateString, message_file, zend_wmerrors_globals, wmerrors_globals) |
| 54 | + STD_PHP_INI_ENTRY("wmerrors.logging_file", "", PHP_INI_ALL, OnUpdateString, logging_file, zend_wmerrors_globals, wmerrors_globals) |
54 | 55 | PHP_INI_END() |
55 | 56 | |
56 | 57 | static void php_wmerrors_init_globals(zend_wmerrors_globals *wmerrors_globals) |
57 | 58 | { |
58 | 59 | wmerrors_globals->message_file = NULL; |
| 60 | + wmerrors_globals->logging_file = NULL; |
59 | 61 | } |
60 | 62 | |
61 | 63 | PHP_MINIT_FUNCTION(wmerrors) |
— | — | @@ -108,6 +110,13 @@ |
109 | 111 | { |
110 | 112 | TSRMLS_FETCH(); |
111 | 113 | |
| 114 | + /* Do not call the custom error handling if: |
| 115 | + * it's not enabled, |
| 116 | + * OR the error is not one of E_{,CORE_,COMPILE_,USER_,RECOVERABLE_}ERROR, |
| 117 | + * OR the error is an E_RECOVERABLE_ERROR and is being thrown as an exception, |
| 118 | + * OR our SAPI is not apache |
| 119 | + * OR it's triggering itself (recursion guard) |
| 120 | + */ |
112 | 121 | if ( !WMERRORS_G(enabled) |
113 | 122 | || (type == E_RECOVERABLE_ERROR && WM_ERROR_HANDLING == EH_THROW && !EG(exception)) |
114 | 123 | || (type != E_ERROR && type != E_CORE_ERROR && type != E_COMPILE_ERROR |
— | — | @@ -136,7 +145,7 @@ |
137 | 146 | |
138 | 147 | static void wmerrors_show_message(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args TSRMLS_DC) |
139 | 148 | { |
140 | | - php_stream *stream; |
| 149 | + php_stream *stream, *log_stream; |
141 | 150 | char *message, *p; |
142 | 151 | int message_len; |
143 | 152 | long maxlen = PHP_STREAM_COPY_ALL; |
— | — | @@ -156,6 +165,14 @@ |
157 | 166 | if (!stream) { |
158 | 167 | return; |
159 | 168 | } |
| 169 | + |
| 170 | + /* Try opening the logging file */ |
| 171 | + log_stream = NULL; |
| 172 | + if (WMERRORS_G(logging_file) && *WMERRORS_G(logging_file) != '\0') |
| 173 | + { |
| 174 | + log_stream = php_stream_open_wrapper(WMERRORS_G(logging_file), "ab", |
| 175 | + ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); |
| 176 | + } |
160 | 177 | |
161 | 178 | /* Don't destroy the caller's va_list */ |
162 | 179 | va_copy(my_args, args); |
— | — | @@ -206,6 +223,10 @@ |
207 | 224 | |
208 | 225 | /* Write the message out */ |
209 | 226 | if (expanded.c) { |
| 227 | + /*php_write(expanded.c, expanded.len TSRMLS_CC);*/ |
| 228 | + if (log_stream) { |
| 229 | + php_stream_write(log_stream, expanded.c, expanded.len TSRMLS_CC); |
| 230 | + } |
210 | 231 | php_write(expanded.c, expanded.len TSRMLS_CC); |
211 | 232 | } |
212 | 233 | |
Index: trunk/php/wmerrors/php_wmerrors.h |
— | — | @@ -24,6 +24,7 @@ |
25 | 25 | ZEND_BEGIN_MODULE_GLOBALS(wmerrors) |
26 | 26 | void (*old_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args); |
27 | 27 | char * message_file; |
| 28 | + char * logging_file; |
28 | 29 | int recursion_guard; |
29 | 30 | int enabled; |
30 | 31 | ZEND_END_MODULE_GLOBALS(wmerrors) |