Index: trunk/php/wmerrors/wmerrors.c |
— | — | @@ -57,6 +57,7 @@ |
58 | 58 | { |
59 | 59 | wmerrors_globals->message_file = NULL; |
60 | 60 | wmerrors_globals->logging_file = NULL; |
| 61 | + wmerrors_globals->logfile_stream = NULL; |
61 | 62 | } |
62 | 63 | |
63 | 64 | PHP_MINIT_FUNCTION(wmerrors) |
— | — | @@ -143,9 +144,14 @@ |
144 | 145 | WMERRORS_G(old_error_cb)(type, error_filename, error_lineno, format, args); |
145 | 146 | } |
146 | 147 | |
| 148 | +static int wmerrors_write_trace(const char *str, uint str_length) { |
| 149 | + php_write((void *)str, str_length TSRMLS_CC); |
| 150 | + php_stream_write(WMERRORS_G(logfile_stream), str, str_length TSRMLS_CC); |
| 151 | +} |
| 152 | + |
147 | 153 | static void wmerrors_show_message(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args TSRMLS_DC) |
148 | 154 | { |
149 | | - php_stream *stream, *log_stream; |
| 155 | + php_stream *stream; |
150 | 156 | char *message, *p; |
151 | 157 | int message_len; |
152 | 158 | long maxlen = PHP_STREAM_COPY_ALL; |
— | — | @@ -153,6 +159,7 @@ |
154 | 160 | int tmp1_len, tmp2_len; |
155 | 161 | smart_str expanded = {0}; |
156 | 162 | va_list my_args; |
| 163 | + zval *trace; |
157 | 164 | |
158 | 165 | /* Is there a sane message_file? */ |
159 | 166 | if (!WMERRORS_G(message_file) || *WMERRORS_G(message_file) == '\0') { |
— | — | @@ -167,10 +174,10 @@ |
168 | 175 | } |
169 | 176 | |
170 | 177 | /* Try opening the logging file */ |
171 | | - log_stream = NULL; |
| 178 | + WMERRORS_G(logfile_stream) = NULL; |
172 | 179 | if (WMERRORS_G(logging_file) && *WMERRORS_G(logging_file) != '\0') |
173 | 180 | { |
174 | | - log_stream = php_stream_open_wrapper(WMERRORS_G(logging_file), "ab", |
| 181 | + WMERRORS_G(logfile_stream) = php_stream_open_wrapper(WMERRORS_G(logging_file), "ab", |
175 | 182 | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); |
176 | 183 | } |
177 | 184 | |
— | — | @@ -224,8 +231,8 @@ |
225 | 232 | /* Write the message out */ |
226 | 233 | if (expanded.c) { |
227 | 234 | /*php_write(expanded.c, expanded.len TSRMLS_CC);*/ |
228 | | - if (log_stream) { |
229 | | - php_stream_write(log_stream, expanded.c, expanded.len TSRMLS_CC); |
| 235 | + if (WMERRORS_G(logfile_stream)) { |
| 236 | + php_stream_write(WMERRORS_G(logfile_stream), expanded.c, expanded.len TSRMLS_CC); |
230 | 237 | } |
231 | 238 | php_write(expanded.c, expanded.len TSRMLS_CC); |
232 | 239 | } |
— | — | @@ -234,6 +241,13 @@ |
235 | 242 | smart_str_free(&expanded); |
236 | 243 | efree(message); |
237 | 244 | va_end(my_args); |
| 245 | + |
| 246 | + /* Write a backtrace */ |
| 247 | + ALLOC_ZVAL(trace); |
| 248 | + Z_UNSET_ISREF_P(trace); |
| 249 | + Z_SET_REFCOUNT_P(trace, 0); |
| 250 | + zend_fetch_debug_backtrace(trace, 0, 0 TSRMLS_CC); |
| 251 | + zend_print_zval_r_ex(wmerrors_write_trace, trace, 4); |
238 | 252 | } |
239 | 253 | |
240 | 254 | |
Index: trunk/php/wmerrors/php_wmerrors.h |
— | — | @@ -27,6 +27,7 @@ |
28 | 28 | char * logging_file; |
29 | 29 | int recursion_guard; |
30 | 30 | int enabled; |
| 31 | + php_stream *logfile_stream; |
31 | 32 | ZEND_END_MODULE_GLOBALS(wmerrors) |
32 | 33 | |
33 | 34 | |