Colored + readable error messages
| From: | Stefan Walk | Date: | Fri, 11 Jul 2003 10:30:43 +0000 |
| Subject: | Colored + readable error messages | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-3358@lists.php.net to get a copy of this message | ||
Hi!
I thought it would be nice to have error messages colored when
html_errors is on - fatal errors in red, warnings in blue, notices in
green or alike. And since it sometimes happens that error messages are
printed on a dark background and are not readable very good, i thought
they should be printed on a white background. I wrote a small patch to
do this, could you have a look at it and tell me what you think? I
attached the cvs diff.
Stefan
--
Regards,
Stefan Walk
<swalk@prp0.prp.physik.tu-darmstadt.de>
Index: main.c =================================================================== RCS file: /repository/php-src/main/main.c,v retrieving revision 1.560 diff -u -r1.560 main.c --- main.c 17 Jun 2003 17:15:02 -0000 1.560 +++ main.c 11 Jul 2003 10:17:30 -0000 @@ -659,6 +659,7 @@ if (display && (EG(error_reporting) & type || (type & E_CORE)) && (PG(log_errors) || PG(display_errors) || (!module_initialized))) { char *error_type_str; + char *error_color_str; switch (type) { case E_ERROR: @@ -666,22 +667,27 @@ case E_COMPILE_ERROR: case E_USER_ERROR: error_type_str = "Fatal error"; + error_color_str = "red"; break; case E_WARNING: case E_CORE_WARNING: case E_COMPILE_WARNING: case E_USER_WARNING: error_type_str = "Warning"; + error_color_str = "blue"; break; case E_PARSE: error_type_str = "Parse error"; + error_color_str = "black"; break; case E_NOTICE: case E_USER_NOTICE: error_type_str = "Notice"; + error_color_str = "green"; break; default: error_type_str = "Unknown error"; + error_color_str = "black"; break; } @@ -705,10 +711,16 @@ } else { char *prepend_string = INI_STR("error_prepend_string"); char *append_string = INI_STR("error_append_string"); - char *error_format = PG(html_errors) ? - "%s<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br />\n%s" - : "%s\n%s: %s in %s on line %d\n%s"; - php_printf(error_format, STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); + if (PG(html_errors)) { + char *error_format = + "%s\n<div style='border: 1px solid black; background-color:white; " + "color: %s; margin: 2px;'><b>%s</b>: %s in <b>%s</b> on line <b>" + "%d</b></div>\n%s"; + php_printf(error_format, STR_PRINT(prepend_string), error_color_str, error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); + } else { + char *error_format = "%s\n%s: %s in %s on line %d\n%s"; + php_printf(error_format, STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); + } } } #if ZEND_DEBUG
Index: main.c =================================================================== RCS file: /repository/php-src/main/main.c,v retrieving revision 1.560 diff -u -r1.560 main.c --- main.c 17 Jun 2003 17:15:02 -0000 1.560 +++ main.c 11 Jul 2003 10:17:30 -0000 @@ -659,6 +659,7 @@ if (display && (EG(error_reporting) & type || (type & E_CORE)) && (PG(log_errors) || PG(display_errors) || (!module_initialized))) { char *error_type_str; + char *error_color_str; switch (type) { case E_ERROR: @@ -666,22 +667,27 @@ case E_COMPILE_ERROR: case E_USER_ERROR: error_type_str = "Fatal error"; + error_color_str = "red"; break; case E_WARNING: case E_CORE_WARNING: case E_COMPILE_WARNING: case E_USER_WARNING: error_type_str = "Warning"; + error_color_str = "blue"; break; case E_PARSE: error_type_str = "Parse error"; + error_color_str = "black"; break; case E_NOTICE: case E_USER_NOTICE: error_type_str = "Notice"; + error_color_str = "green"; break; default: error_type_str = "Unknown error"; + error_color_str = "black"; break; } @@ -705,10 +711,16 @@ } else { char *prepend_string = INI_STR("error_prepend_string"); char *append_string = INI_STR("error_append_string"); - char *error_format = PG(html_errors) ? - "%s<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br />\n%s" - : "%s\n%s: %s in %s on line %d\n%s"; - php_printf(error_format, STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); + if (PG(html_errors)) { + char *error_format = + "%s\n<div style='border: 1px solid black; background-color:white; " + "color: %s; margin: 2px;'><b>%s</b>: %s in <b>%s</b> on line <b>" + "%d</b></div>\n%s"; + php_printf(error_format, STR_PRINT(prepend_string), error_color_str, error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); + } else { + char *error_format = "%s\n%s: %s in %s on line %d\n%s"; + php_printf(error_format, STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); + } } } #if ZEND_DEBUG