r81991 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81990‎ | r81991 | r81992 >
Date:20:25, 11 February 2011
Author:catrope
Status:ok
Tags:
Comment:
wmerrors: Add capability for logging to a file. Implementing UDP logging would probably be useful as well
Modified paths:
  • /trunk/php/wmerrors/php_wmerrors.h (modified) (history)
  • /trunk/php/wmerrors/wmerrors.c (modified) (history)

Diff [purge]

Index: trunk/php/wmerrors/wmerrors.c
@@ -50,11 +50,13 @@
5151 PHP_INI_BEGIN()
5252 STD_PHP_INI_BOOLEAN("wmerrors.enabled", "0", PHP_INI_ALL, OnUpdateBool, enabled, zend_wmerrors_globals, wmerrors_globals )
5353 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)
5455 PHP_INI_END()
5556
5657 static void php_wmerrors_init_globals(zend_wmerrors_globals *wmerrors_globals)
5758 {
5859 wmerrors_globals->message_file = NULL;
 60+ wmerrors_globals->logging_file = NULL;
5961 }
6062
6163 PHP_MINIT_FUNCTION(wmerrors)
@@ -108,6 +110,13 @@
109111 {
110112 TSRMLS_FETCH();
111113
 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+ */
112121 if ( !WMERRORS_G(enabled)
113122 || (type == E_RECOVERABLE_ERROR && WM_ERROR_HANDLING == EH_THROW && !EG(exception))
114123 || (type != E_ERROR && type != E_CORE_ERROR && type != E_COMPILE_ERROR
@@ -136,7 +145,7 @@
137146
138147 static void wmerrors_show_message(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args TSRMLS_DC)
139148 {
140 - php_stream *stream;
 149+ php_stream *stream, *log_stream;
141150 char *message, *p;
142151 int message_len;
143152 long maxlen = PHP_STREAM_COPY_ALL;
@@ -156,6 +165,14 @@
157166 if (!stream) {
158167 return;
159168 }
 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+ }
160177
161178 /* Don't destroy the caller's va_list */
162179 va_copy(my_args, args);
@@ -206,6 +223,10 @@
207224
208225 /* Write the message out */
209226 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+ }
210231 php_write(expanded.c, expanded.len TSRMLS_CC);
211232 }
212233
Index: trunk/php/wmerrors/php_wmerrors.h
@@ -24,6 +24,7 @@
2525 ZEND_BEGIN_MODULE_GLOBALS(wmerrors)
2626 void (*old_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
2727 char * message_file;
 28+ char * logging_file;
2829 int recursion_guard;
2930 int enabled;
3031 ZEND_END_MODULE_GLOBALS(wmerrors)

Follow-up revisions

RevisionCommit summaryAuthorDate
r82015Removed some leaks (internal to the request)....platonides14:49, 12 February 2011

Status & tagging log