Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 89346381d9fb64d9ee8827de5f073355 > files > 55

php-pear-HTML_Progress2-2.4.1-3mdv2010.0.noarch.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>
      Error Context Display
    </title>
    <link rel="stylesheet" href="book.css" type="text/css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.69.1" />
    <link rel="start" href="index.html" title="HTML_Progress2 Manual" />
    <link rel="up" href="ch16.html" title=
    "Chapter&nbsp;16.&nbsp;Error Handler" />
    <link rel="prev" href="ch16s03.html" title=
    "Controlling error generation " />
    <link rel="next" href="ch16s05.html" title=
    "Custom Error Message Generation " />
    <style type="text/css">
/*<![CDATA[*/
    body {
    background-color: white;
    color: black;
    }
    :link { color: #0000FF }
    :visited { color: #840084 }
    :active { color: #0000FF }
    p.c4 {font-weight: bold}
    div.c3 {margin-left: 0.5in; margin-right: 0.5in;}
    div.c2 {font-family: monospace;}
    h2.c1 {clear: both}
    /*]]>*/
    </style>
  </head>
  <body>
    <table class="progress2Header">
      <tr>
        <td>
          <img src="img/pear_progress2.gif" align="left" alt=
          "PEAR Progress2 logo" />
          <h1>
            HTML_Progress2 : The Definitive Guide
          </h1>
          <div class="navheader">
            <table width="100%" summary="Navigation header">
              <tr>
                <th colspan="3" align="center">
                  Error Context Display
                </th>
              </tr>
              <tr>
                <td width="20%" align="left">
                  <a accesskey="p" href="ch16s03.html">Prev</a>&nbsp;
                </td>
                <th width="60%" align="center">
                  Chapter&nbsp;16.&nbsp;Error Handler
                </th>
                <td width="20%" align="right">
                  &nbsp;<a accesskey="n" href="ch16s05.html">Next</a>
                </td>
              </tr>
            </table>
          </div>
        </td>
      </tr>
    </table>
    <div class="sect1" lang="en" xml:lang="en">
      <div class="titlepage">
        <h2 class="title c1">
          <a name="id4798673" id="id4798673"></a>Error Context Display
        </h2>
      </div>
      <p>
        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.
      </p>
      <p>
        With this example we will change display and log renders.
      </p>
      <div class="php c2">
        <ol>
          <li class="li1">
            <div class="de1">
              <span class="kw2">&lt;?php</span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              <span class="kw1">require_once</span> <span class=
              "st0">'HTML/Progress2.php'</span><span class="sy0">;</span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              &nbsp;
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              <span class="re1">$displayConfig</span> <span class=
              "sy0">=</span> <span class="kw3">array</span><span class=
              "br0">(</span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              &nbsp; &nbsp; <span class="st0">'lineFormat'</span> <span class=
              "sy0">=&gt;</span> <span class="st0">'&lt;b&gt;%1$s&lt;/b&gt;:
              %2$s&lt;br /&gt;%3$s'</span><span class="sy0">,</span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              &nbsp; &nbsp; <span class="st0">'contextFormat'</span>
              <span class="sy0">=&gt;</span> &nbsp; <span class=
              "st0">'&lt;b&gt;File:&lt;/b&gt; %1$s &lt;br /&gt;'</span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
              &nbsp; &nbsp; &nbsp;<span class="sy0">.</span> <span class=
              "st0">'&lt;b&gt;Line:&lt;/b&gt; %2$s &lt;br /&gt;'</span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
              &nbsp; &nbsp; &nbsp;<span class="sy0">.</span> <span class=
              "st0">'&lt;b&gt;Function:&lt;/b&gt; %3$s '</span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              <span class="br0">)</span><span class="sy0">;</span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              <span class="re1">$logConfig</span> <span class="sy0">=</span>
              <span class="kw3">array</span><span class="br0">(</span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              &nbsp; &nbsp; <span class="st0">'lineFormat'</span> <span class=
              "sy0">=&gt;</span> <span class="st0">'%1$s %2$s [%3$s]
              %4$s'</span><span class="sy0">,</span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              &nbsp; &nbsp; <span class="st0">'timeFormat'</span> <span class=
              "sy0">=&gt;</span> <span class="st0">'%b'</span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              <span class="br0">)</span><span class="sy0">;</span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              &nbsp;
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              <span class="re1">$prefs</span> <span class="sy0">=</span>
              <span class="kw3">array</span><span class="br0">(</span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              &nbsp; &nbsp; <span class="st0">'handler'</span> <span class=
              "sy0">=&gt;</span> <span class="kw3">array</span><span class=
              "br0">(</span><span class="st0">'display'</span> <span class=
              "sy0">=&gt;</span> <span class=
              "re1">$displayConfig</span><span class="sy0">,</span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
              &nbsp; &nbsp; &nbsp;<span class="st0">'log'</span> &nbsp; &nbsp;
              <span class="sy0">=&gt;</span> <span class=
              "re1">$logConfig</span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              <span class="br0">)</span><span class="br0">)</span><span class=
              "sy0">;</span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              &nbsp;
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              <span class="re1">$meter</span> <span class="sy0">=</span>
              <span class="kw2">new</span> HTML_Progress2<span class=
              "br0">(</span><span class="re1">$prefs</span><span class=
              "br0">)</span><span class="sy0">;</span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              <span class="co1">// ...</span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              <span class="re1">$result</span> <span class="sy0">=</span>
              <span class="re1">$meter</span><span class=
              "sy0">-&gt;</span><span class="me1">setValue</span><span class=
              "br0">(</span><span class="st0">'37'</span><span class=
              "br0">)</span><span class="sy0">;</span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              <span class="kw2">?&gt;</span>
            </div>
          </li>
        </ol>
      </div>
      <p>
        Display render will give something like:
      </p>
      <div class="informalexample screenco">
        <pre class="screen">
Exception<a name="error.2.level" id="error.2.level"></a><img src=
"img/callouts/1.gif" alt="1" border=
"0" />: invalid input, parameter #1 "$val" was expecting "integer", instead got "string"<a name="error.2.message"
id="error.2.message"></a><img src="img/callouts/2.gif" alt="2" border="0" />
File: [path_to]\[filename] <a name="error.2.context" id=
"error.2.context"></a><img src="img/callouts/3.gif" alt="3" border="0" />
Line: 23 <a name="error.2.context" id="error.2.context"></a><img src=
"img/callouts/3.gif" alt="3" border="0" />
Function: html_progress2-&gt;setvalue <a name="error.2.context" id=
"error.2.context"></a><img src="img/callouts/3.gif" alt="3" border="0" />
     
</pre>
        <div class="calloutlist">
          <table border="0" summary="Callout list">
            <tr>
              <td width="5%" valign="top" align="left">
                <a href="#error.2.level"><img src="img/callouts/1.gif" alt="1"
                border="0" /></a>
              </td>
              <td valign="top" align="left">
                <p>
                  error level
                </p>
              </td>
            </tr>
            <tr>
              <td width="5%" valign="top" align="left">
                <a href="#error.2.message"><img src="img/callouts/2.gif" alt=
                "2" border="0" /></a>
              </td>
              <td valign="top" align="left">
                <p>
                  message body with context informations
                </p>
              </td>
            </tr>
            <tr>
              <td width="5%" valign="top" align="left">
                <a href="#error.2.context"><img src="img/callouts/3.gif" alt=
                "3" border="0" /></a>
              </td>
              <td valign="top" align="left">
                <p>
                  call context (file, line, function)
                </p>
              </td>
            </tr>
          </table>
        </div>
      </div>
      <p>
        Log render will give something like:
      </p>
      <div class="informalexample screenco">
        <pre class="screen">
Aug 127.0.0.1<a name="error.3.context" id="error.3.context"></a><img src=
"img/callouts/1.gif" alt="1" border="0" /> [exception<a name="error.3.level"
id="error.3.level"></a><img src="img/callouts/2.gif" alt="2" border=
"0" />] invalid input, parameter #1 "$val" was expecting "integer", instead got "string"<a name="error.3.message"
id="error.3.message"></a><img src="img/callouts/3.gif" alt="3" border="0" />
     
</pre>
        <div class="calloutlist">
          <table border="0" summary="Callout list">
            <tr>
              <td width="5%" valign="top" align="left">
                <a href="#error.3.context"><img src="img/callouts/1.gif" alt=
                "1" border="0" /></a>
              </td>
              <td valign="top" align="left">
                <p>
                  client ip address and execution date
                </p>
              </td>
            </tr>
            <tr>
              <td width="5%" valign="top" align="left">
                <a href="#error.3.level"><img src="img/callouts/2.gif" alt="2"
                border="0" /></a>
              </td>
              <td valign="top" align="left">
                <p>
                  error level
                </p>
              </td>
            </tr>
            <tr>
              <td width="5%" valign="top" align="left">
                <a href="#error.3.message"><img src="img/callouts/3.gif" alt=
                "3" border="0" /></a>
              </td>
              <td valign="top" align="left">
                <p>
                  message body with context informations
                </p>
              </td>
            </tr>
          </table>
        </div>
      </div>
      <div class="note c3">
        <table border="0" summary="Note">
          <tr>
            <td rowspan="2" align="center" valign="top" width="48">
              <img alt="[Note]" src="img/admons/note.png" />
            </td>
            <th align="left">
              Note
            </th>
          </tr>
          <tr>
            <td align="left" valign="top">
              To have both display and log output, check the <code class=
              "filename">php.ini</code><span class=
              "emphasis"><em>display_errors</em></span> and <span class=
              "emphasis"><em>log_errors</em></span> values : must be set to
              <code class="constant">TRUE</code>.
            </td>
          </tr>
        </table>
      </div>
      <p>
        Let rewiew, step by step, how to get such results.
      </p>
      <p>
        Remember that with default classes, there are two drivers :
        <span class="emphasis"><em>display</em></span> and <span class=
        "emphasis"><em>log</em></span> that have both their own configuration
        parameters. You can override these parameters values with the
        <span class="bold"><strong>handler</strong></span> entry in the hash of
        first argument of the HTML_Progress2 class constructor.
      </p>
      <p>
        We did it here with the <em class="parameter"><code>$prefs</code></em>
        variable; its a two keys associative array. First key <span class=
        "emphasis"><em>display</em></span> defines the display driver values,
        and the second key <span class="emphasis"><em>log</em></span> defines
        the log driver values.
      </p>
      <p>
        Review the <span class="emphasis"><em>display</em></span> driver custom
        values. Only two keys: <span class="simplelist">lineFormat,
        contextFormat</span> are redefined, thats means remains key
        <span class="simplelist">eol</span> keep its default value. See table
        below.
      </p>
      <div class="table">
        <a name="id4803623" id="id4803623"></a>
        <p class="title c4">
          Table&nbsp;16.2.&nbsp;Display driver configuration parameters
        </p>
        <table summary="Display driver configuration parameters" border="1">
          <colgroup>
            <col />
            <col />
            <col />
            <col />
          </colgroup>
          <thead>
            <tr>
              <th>
                Parameter
              </th>
              <th>
                Type
              </th>
              <th>
                Default
              </th>
              <th>
                Description
              </th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>
                eol
              </td>
              <td>
                string
              </td>
              <td>
                &lt;br /&gt;\n
              </td>
              <td>
                The end-on-line character sequence
              </td>
            </tr>
            <tr>
              <td>
                lineFormat
              </td>
              <td>
                string
              </td>
              <td>
                &lt;b&gt;%1$s&lt;/b&gt;: %2$s %3$s
              </td>
              <td>
                Log line format specification:
                <div class="itemizedlist">
                  <ul type="disc">
                    <li>1$ = error level
                    </li>
                    <li>2$ = error message (body)
                    </li>
                    <li>3$ = error context
                    </li>
                  </ul>
                </div>
              </td>
            </tr>
            <tr>
              <td>
                contextFormat
              </td>
              <td>
                string
              </td>
              <td>
                in &lt;b&gt;%3$s&lt;/b&gt; (file &lt;b&gt;%1$s&lt;/b&gt; on
                line &lt;b&gt;%2$s&lt;/b&gt;)
              </td>
              <td>
                Context format (class, file, line) specification:
                <div class="itemizedlist">
                  <ul type="disc">
                    <li>1$ = script file name
                    </li>
                    <li>2$ = line in script file
                    </li>
                    <li>3$ = class/method names
                    </li>
                  </ul>
                </div>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
      <div class="tip c3">
        <table border="0" summary="Tip">
          <tr>
            <td rowspan="2" align="center" valign="top" width="48">
              <img alt="[Tip]" src="img/admons/tip.png" />
            </td>
            <th align="left">
              Tip
            </th>
          </tr>
          <tr>
            <td align="left" valign="top">
              If you don't wish to see context information in the error
              message, then remove the parameter %3$ in the <span class=
              "emphasis"><em>lineFormat</em></span> option even if <span class=
              "emphasis"><em>contextFormat</em></span> is set.
            </td>
          </tr>
        </table>
      </div>
      <p>
        Review now the <span class="emphasis"><em>log</em></span> driver custom
        values. Only two keys <span class="simplelist">lineFormat,
        timeFormat</span> are redefined, thats means six remains keys
        <span class="simplelist">eol, contextFormat, ident, message_type,
        destination, extra_headers</span> keep their default values. See table
        below.
      </p>
      <div class="table">
        <a name="id4803814" id="id4803814"></a>
        <p class="title c4">
          Table&nbsp;16.3.&nbsp;Log driver configuration parameters
        </p>
        <table summary="Log driver configuration parameters" border="1">
          <colgroup>
            <col />
            <col />
            <col />
            <col />
          </colgroup>
          <thead>
            <tr>
              <th>
                Parameter
              </th>
              <th>
                Type
              </th>
              <th>
                Default
              </th>
              <th>
                Description
              </th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>
                eol
              </td>
              <td>
                string
              </td>
              <td>
                \n
              </td>
              <td>
                The end-on-line character sequence
              </td>
            </tr>
            <tr>
              <td>
                lineFormat
              </td>
              <td>
                string
              </td>
              <td>
                %1$s %2$s [%3$s] %4$s %5$s
              </td>
              <td>
                Log line format specification:
                <div class="itemizedlist">
                  <ul type="disc">
                    <li>$1 = time error
                    </li>
                    <li>2$ = ident (client ip)
                    </li>
                    <li>3$ = error level
                    </li>
                    <li>4$ = error message (body)
                    </li>
                    <li>5$ = error context
                    </li>
                  </ul>
                </div>
              </td>
            </tr>
            <tr>
              <td>
                contextFormat
              </td>
              <td>
                string
              </td>
              <td>
                in %3$s (file %1$s on line %2$s)
              </td>
              <td>
                Context format (class, file, line) specification:
                <div class="itemizedlist">
                  <ul type="disc">
                    <li>1$ = script file name
                    </li>
                    <li>2$ = line in script file
                    </li>
                    <li>3$ = class/method names
                    </li>
                  </ul>
                </div>
              </td>
            </tr>
            <tr>
              <td>
                timeFormat
              </td>
              <td>
                string
              </td>
              <td>
                %b %d %H:%M:%S
              </td>
              <td>
                Time stamp format used by <a class="external" href=
                "http://www.php.net/manual-lookup.php?pattern=strftime" title=
                "http://www.php.net/manual-lookup.php?pattern=strftime">strftime</a>
              </td>
            </tr>
            <tr>
              <td>
                ident
              </td>
              <td>
                string
              </td>
              <td>
                REMOTE_ADDR
              </td>
              <td>
                Client IP
              </td>
            </tr>
            <tr>
              <td>
                message_type
              </td>
              <td>
                string
              </td>
              <td>
                3
              </td>
              <td>
                Destination type used by <a class="external" href=
                "http://www.php.net/manual-lookup.php?pattern=error_log" title=
                "http://www.php.net/manual-lookup.php?pattern=error_log">error_log</a>
              </td>
            </tr>
            <tr>
              <td>
                destination
              </td>
              <td>
                string
              </td>
              <td>
                html_progress2_error.log
              </td>
              <td>
                Destination name used by <a class="external" href=
                "http://www.php.net/manual-lookup.php?pattern=error_log" title=
                "http://www.php.net/manual-lookup.php?pattern=error_log">error_log</a>
              </td>
            </tr>
            <tr>
              <td>
                extra_headers
              </td>
              <td>
                string
              </td>
              <td>
                <code class="constant">NULL</code>
              </td>
              <td>
                Extra headers depending of destination type
              </td>
            </tr>
          </tbody>
        </table>
      </div>
      <div class="tip c3">
        <table border="0" summary="Tip">
          <tr>
            <td rowspan="2" align="center" valign="top" width="48">
              <img alt="[Tip]" src="img/admons/tip.png" />
            </td>
            <th align="left">
              Tip
            </th>
          </tr>
          <tr>
            <td align="left" valign="top">
              If you don't wish to see context information in the error
              message, then remove the parameter %5$ in the <span class=
              "emphasis"><em>lineFormat</em></span> option even if <span class=
              "emphasis"><em>contextFormat</em></span> is set.
            </td>
          </tr>
        </table>
      </div>
    </div>
    <table class="progress2Footer">
      <tr>
        <td align="left">
          HTML_Progress2 : The Definitive Guide
        </td>
        <td align="right">
          v 2.4.0 : April 20, 2007
        </td>
      </tr>
    </table>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left">
            <a accesskey="p" href="ch16s03.html">Prev</a>&nbsp;
          </td>
          <td width="20%" align="center">
            <a accesskey="u" href="ch16.html">Up</a>
          </td>
          <td width="40%" align="right">
            &nbsp;<a accesskey="n" href="ch16s05.html">Next</a>
          </td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">
            Controlling error generation &nbsp;
          </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top">
            &nbsp;Custom Error Message Generation
          </td>
        </tr>
      </table>
    </div>
  </body>
</html>