![]() HTML_Progress2 : 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 rendering of context information.
With this example we will change display and log renders.
<?php require_once 'HTML/Progress2.php'; $displayConfig = array( 'lineFormat' => '<b>%1$s</b>: %2$s<br />%3$s', 'contextFormat' => '<b>File:</b> %1$s <br />' . '<b>Line:</b> %2$s <br />' . '<b>Function:</b> %3$s ' ); $logConfig = array( 'lineFormat' => '%1$s %2$s [%3$s] %4$s', 'timeFormat' => '%b' ); $prefs = array( 'handler' => array('display' => $displayConfig, 'log' => $logConfig )); $meter = new HTML_Progress2($prefs); // ... $result = $meter->setValue('37'); ?>
Display render will give something like:
Log render will give something like:
![]() |
Note |
---|---|
To have both display and log output, check the
php.ini display_errors and
log_errors values : must be set to
TRUE .
|
Let rewiew, 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 first argument of the HTML_Progress2 class constructor.
We did it here with the $prefs
variable; its 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 13.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 13.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_progress2_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_Progress2 : The Definitive Guide | v 1.0.0 : September 23, 2005 |