HTML_CSS : The Definitive Guide |
In some cases, you may want to customize error generation. For instance, for each error (basic/exception), it is useful to include file, line number, and class/function context information in order to trace it. The default option will be sufficient for most cases but you want perhaps customize the output format (render) of context information.
With this example we will change display and log renders.
Display render will give something like:
Exception: invalid input, parameter #3 "$value" was expecting "string", instead got "integer" File: [path_to]\[filename] Line: 22 Function: html_css->setstyle
Log render will give something like:
Jun 127.0.0.1 [exception] invalid input, parameter #3 "$value" was expecting "string", instead got "integer"
Note | |
---|---|
To have both display and log output, check the |
Let review, step by step, how to get such results.
Remember that with default classes, there are two drivers : display and log that have both their own configuration parameters. You can override these parameters values with the handler entry in the hash of second argument of the HTML_CSS class constructor.
We did it here with the $prefs
variable; it's a two keys associative array. First key display defines the display driver values,
and the second key log defines
the log driver values.
Review the display driver custom values. Only two keys: lineFormat, contextFormat are redefined, thats means remains key eol keep its default value. See table below.
Table 10.2. Display driver configuration parameters
Parameter | Type | Default | Description |
---|---|---|---|
eol | string | <br />\n | The end-on-line character sequence |
lineFormat | string | <b>%1$s</b>: %2$s %3$s |
Log line format specification:
|
contextFormat | string | in <b>%3$s</b> (file <b>%1$s</b> on line <b>%2$s</b>) |
Context format (class, file, line) specification:
|
Tip | |
---|---|
If you don't wish to see context information in the error message, then remove the parameter %3$ in the lineFormat option even if contextFormat is set. |
Review now the log driver custom values. Only two keys lineFormat, timeFormat are redefined, thats means six remains keys eol, contextFormat, ident, message_type, destination, extra_headers keep their default values. See table below.
Table 10.3. Log driver configuration parameters
Parameter | Type | Default | Description |
---|---|---|---|
eol | string | \n | The end-on-line character sequence |
lineFormat | string | %1$s %2$s [%3$s] %4$s %5$s |
Log line format specification:
|
contextFormat | string | in %3$s (file %1$s on line %2$s) |
Context format (class, file, line) specification:
|
timeFormat | string | %b %d %H:%M:%S | Time stamp format used by strftime |
ident | string | REMOTE_ADDR | Client IP |
message_type | string | 3 | Destination type used by error_log |
destination | string | html_css_error.log | Destination name used by error_log |
extra_headers | string |
NULL
|
Extra headers depending of destination type |
Tip | |
---|---|
If you don't wish to see context information in the error message, then remove the parameter %5$ in the lineFormat option even if contextFormat is set. |
HTML_CSS : The Definitive Guide | v 1.5.0 : January 15, 2008 |