Index: trunk/php/wmerrors/wmerrors.c |
— | — | @@ -62,6 +62,7 @@ |
63 | 63 | wmerrors_globals->message_file = NULL; |
64 | 64 | wmerrors_globals->logging_file = NULL; |
65 | 65 | wmerrors_globals->log_level = 0; |
| 66 | + wmerrors_globals->log_buffer.c = NULL; |
66 | 67 | } |
67 | 68 | |
68 | 69 | PHP_MINIT_FUNCTION(wmerrors) |
— | — | @@ -160,7 +161,7 @@ |
161 | 162 | int err; char *errstr = NULL; |
162 | 163 | struct timeval tv; |
163 | 164 | |
164 | | - if ( strncmp( stream_name, "tcp://", 6 ) ) { |
| 165 | + if ( strncmp( stream_name, "tcp://", 6 ) && strncmp( stream_name, "udp://", 6 ) ) { |
165 | 166 | /* Is it a wrapper? */ |
166 | 167 | stream = php_stream_open_wrapper(stream_name, "ab", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); |
167 | 168 | } else { |
— | — | @@ -179,16 +180,18 @@ |
180 | 181 | } |
181 | 182 | |
182 | 183 | /* Callback for zend_print_zval_r_ex() |
183 | | - * Gets the file to write from the module global logfile_stream. |
| 184 | + * Writes to the global buffer |
184 | 185 | */ |
185 | 186 | static int wmerrors_write_trace(const char *str, uint str_length) { |
186 | 187 | TSRMLS_FETCH(); |
187 | | - return php_stream_write(WMERRORS_G(logfile_stream), str, str_length); |
| 188 | + smart_str_appendl(&WMERRORS_G(log_buffer), str, str_length); |
| 189 | + return str_length; |
188 | 190 | } |
189 | 191 | |
190 | 192 | static void wmerrors_log_error(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args TSRMLS_DC) { |
191 | 193 | char *tmp1; zval *trace; char *error_time_str; |
192 | 194 | int tmp1_len; va_list my_args; |
| 195 | + php_stream *logfile_stream; |
193 | 196 | |
194 | 197 | if ( !WMERRORS_G(enabled) || !WMERRORS_G(log_level) ) { |
195 | 198 | /* Redundant with the caller */ |
— | — | @@ -201,8 +204,8 @@ |
202 | 205 | } |
203 | 206 | |
204 | 207 | /* Try opening the logging file */ |
205 | | - WMERRORS_G(logfile_stream) = open_logging_file( WMERRORS_G(logging_file) ); |
206 | | - if ( !WMERRORS_G(logfile_stream) ) { |
| 208 | + logfile_stream = open_logging_file( WMERRORS_G(logging_file) ); |
| 209 | + if ( !logfile_stream ) { |
207 | 210 | return; |
208 | 211 | } |
209 | 212 | |
— | — | @@ -213,7 +216,7 @@ |
214 | 217 | |
215 | 218 | /* Log the error (log_level >= 1) */ |
216 | 219 | error_time_str = php_format_date("d-M-Y H:i:s", 11, time(NULL), 0 TSRMLS_CC); |
217 | | - php_stream_printf(WMERRORS_G(logfile_stream) TSRMLS_CC, "[%s UTC] %s: %.*s at %s on line %u%s", error_time_str, error_type_to_string(type), tmp1_len, tmp1, error_filename, error_lineno, PHP_EOL); |
| 220 | + php_stream_printf(logfile_stream TSRMLS_CC, "[%s UTC] %s: %.*s at %s on line %u%s", error_time_str, error_type_to_string(type), tmp1_len, tmp1, error_filename, error_lineno, PHP_EOL); |
218 | 221 | efree(error_time_str); |
219 | 222 | efree(tmp1); |
220 | 223 | |
— | — | @@ -223,9 +226,10 @@ |
224 | 227 | zend_fetch_debug_backtrace(trace, 0, 0 TSRMLS_CC); |
225 | 228 | zend_print_zval_r_ex(wmerrors_write_trace, trace, 4 TSRMLS_CC); |
226 | 229 | FREE_ZVAL(trace); |
| 230 | + php_stream_write(logfile_stream, WMERRORS_G(log_buffer).c, WMERRORS_G(log_buffer).len TSRMLS_CC); |
227 | 231 | } |
228 | 232 | |
229 | | - php_stream_close( WMERRORS_G(logfile_stream) ); |
| 233 | + php_stream_close( logfile_stream ); |
230 | 234 | } |
231 | 235 | |
232 | 236 | static void wmerrors_show_message(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args TSRMLS_DC) |
Index: trunk/php/wmerrors/php_wmerrors.h |
— | — | @@ -15,6 +15,8 @@ |
16 | 16 | #include "TSRM.h" |
17 | 17 | #endif |
18 | 18 | |
| 19 | +#include "ext/standard/php_smart_str_public.h" |
| 20 | + |
19 | 21 | PHP_MINIT_FUNCTION(wmerrors); |
20 | 22 | PHP_MSHUTDOWN_FUNCTION(wmerrors); |
21 | 23 | PHP_RINIT_FUNCTION(wmerrors); |
— | — | @@ -27,7 +29,7 @@ |
28 | 30 | int recursion_guard; |
29 | 31 | int enabled; |
30 | 32 | long int log_level; |
31 | | - php_stream *logfile_stream; |
| 33 | + smart_str log_buffer; |
32 | 34 | ZEND_END_MODULE_GLOBALS(wmerrors) |
33 | 35 | |
34 | 36 | |