cvs: pear /HTML_Progress/examples/errorstack display184.php display2.php display_errors.html display_errors.php log_errors.html log_errors.php

From: Date: Mon, 05 Jul 2004 21:31:06 +0000
Subject: cvs: pear /HTML_Progress/examples/errorstack display184.php display2.php display_errors.html display_errors.php log_errors.html log_errors.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-21546@lists.php.net to get a copy of this message
farell Mon Jul 5 17:31:06 2004 EDT Added files: /pear/HTML_Progress/examples/errorstack display184.php display2.php display_errors.html display_errors.php log_errors.html log_errors.php Log: some examples of how to manage errors

http://cvs.php.net/co.php/pear/HTML_Progress/examples/errorstack/display184.php?r=1.1&p=1 Index: pear/HTML_Progress/examples/errorstack/display184.php +++ pear/HTML_Progress/examples/errorstack/display184.php <?php /** * $Header: /usr/repository/pear/HTML_Progress/examples/errorstack/display184.php,v 1.1 2004/07/05 21:31:06 farell Exp $ * * @version $Revision: 1.1 $ * @package Log */ /** * The Log_display class is a concrete implementation of the Log:: * abstract class which writes message into browser in usual PHP maner. * This may be useful because when you use PEAR::setErrorHandling in * PEAR_ERROR_CALLBACK mode error messages are not displayed by * PHP error handler. * * @author Paul Yanchenko <pusher@inaco.ru> * @since Log 1.8.0 * @package Log * * @example display.php Using the display handler. */ class Log_display extends Log { /** * String to output before an error message * @var string * @access private */ var $_error_prepend = ''; /** * String to output after an error message * @var string * @access private */ var $_error_append = ''; /** * Constructs a new Log_display object. * * @param string $name Ignored. * @param string $ident The identity string. * @param array $conf The configuration array. * @param int $level Log messages up to and including this level. * @access public */ function Log_display($name = '', $ident = '', $conf = array(), $level = PEAR_LOG_DEBUG) { $this->_id = md5(microtime()); $this->_ident = $ident; $this->_mask = Log::UPTO($level); if (!empty($conf['error_prepend'])) { $this->_error_prepend = $conf['error_prepend']; } else { $this->_error_prepend = ini_get('error_prepend_string'); } if (!empty($conf['error_append'])) { $this->_error_append = $conf['error_append']; } else { $this->_error_append = ini_get('error_append_string'); } } /** * Writes $message to the text browser. Also, passes the message * along to any Log_observer instances that are observing this Log. * * @param mixed $message String or object containing the message to log. * @param string $priority The priority of the message. Valid * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT, * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING, * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG. * @return boolean True on success or false on failure. * @access public */ function log($message, $priority = null) { /* If a priority hasn't been specified, use the default value. */ if ($priority === null) { $priority = $this->_priority; } /* Abort early if the priority is above the maximum logging level. */ if (!$this->_isMasked($priority)) { return false; } /* Extract the string representation of the message. */ $message = $this->_extractMessage($message); /* Build and output the complete log line. */ echo $this->_error_prepend . '<b>' . ucfirst($this->priorityToString($priority)) . '</b>: '. htmlspecialchars($message) . $this->_error_append . "<br />\n"; /* Notify observers about this log message. */ $this->_announce(array('priority' => $priority, 'message' => $message)); return true; } } ?> http://cvs.php.net/co.php/pear/HTML_Progress/examples/errorstack/display2.php?r=1.1&p=1 Index: pear/HTML_Progress/examples/errorstack/display2.php +++ pear/HTML_Progress/examples/errorstack/display2.php <?php /** * $Header: /usr/repository/pear/HTML_Progress/examples/errorstack/display2.php,v 1.1 2004/07/05 21:31:06 farell Exp $ * * @version $Revision: 1.1 $ * @package Log */ /** * The Log_display class is a concrete implementation of the Log:: * abstract class which writes message into browser in usual PHP maner. * This may be useful because when you use PEAR::setErrorHandling in * PEAR_ERROR_CALLBACK mode error messages are not displayed by * PHP error handler. * * @author Paul Yanchenko <pusher@inaco.ru> * @since Log 1.8.0 * @package Log * * @example display.php Using the display handler. */ class Log_display extends Log { /** * String to output before an error message * @var string * @access private */ var $_error_prepend = ''; /** * String to output after an error message * @var string * @access private */ var $_error_append = ''; var $_printf = '<b>%s </b>: %s in <b>%s</b> (<b>%s</b> at line <b>%s</b>)'; var $_ereg = 'in (.*) \(file (.*) at line (.*)\)'; /** * Constructs a new Log_display object. * * @param string $name Ignored. * @param string $ident The identity string. * @param array $conf The configuration array. * @param int $level Log messages up to and including this level. * @access public */ function Log_display($name = '', $ident = '', $conf = array(), $level = PEAR_LOG_DEBUG) { $this->_id = md5(microtime()); $this->_ident = $ident; $this->_mask = Log::UPTO($level); if (!empty($conf['error_prepend'])) { $this->_error_prepend = $conf['error_prepend']; } else { $this->_error_prepend = ini_get('error_prepend_string'); } if (!empty($conf['error_append'])) { $this->_error_append = $conf['error_append']; } else { $this->_error_append = ini_get('error_append_string'); } if (!empty($conf['printf'])) { $this->_printf = $conf['printf']; } if (!empty($conf['ereg'])) { $this->_ereg = $conf['ereg']; } } /** * Writes $message to the text browser. Also, passes the message * along to any Log_observer instances that are observing this Log. * * @param mixed $message String or object containing the message to log. * @param string $priority The priority of the message. Valid * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT, * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING, * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG. * @return boolean True on success or false on failure. * @access public */ function log($message, $priority = null) { /* If a priority hasn't been specified, use the default value. */ if ($priority === null) { $priority = $this->_priority; } /* Abort early if the priority is above the maximum logging level. */ if (!$this->_isMasked($priority)) { return false; } /* Extract the string representation of the message. */ $message = $this->_extractMessage($message); /* Build and output the complete log line. */ if (ereg($this->_ereg, $message, $matches)) { $message = str_replace($matches[0], '', $message); echo $this->_error_prepend . @sprintf($this->_printf, ucfirst($this->priorityToString($priority)), $message, $matches[1], $matches[2], $matches[3], $matches[4]) . $this->_error_append . "<br />\n"; } else { echo $this->_error_prepend . '<b>' . ucfirst($this->priorityToString($priority)) . '</b>: '. htmlspecialchars($message) . $this->_error_append . "<br />\n"; } /* Notify observers about this log message. */ $this->_announce(array('priority' => $priority, 'message' => $message)); return true; } } ?> http://cvs.php.net/co.php/pear/HTML_Progress/examples/errorstack/display_errors.html?r=1.1&p=1 Index: pear/HTML_Progress/examples/errorstack/display_errors.html +++ pear/HTML_Progress/examples/errorstack/display_errors.html <!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 name="robots" content="index,nofollow" /> <meta name="keywords" content"="HTML_Progress, PEAR_ErrorStack, API error, progress meter" /> <meta name="description" content="all API HTML_Progress errors are logs on STDOUT (browser)" /> <meta name="author" content="Laurent Laville" /> <title>PEAR::HTML::Progress example: ErrorStack on STDOUT</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="../examples.css" /> </head> <body> <a name="top"> <p><a href="../index.html"><img src="../images/home.gif" alt="Examples TOC"/>examples</a></p> <h1><span class="chapter">Browser </span></h1> <p align="right">$Date: 2004/07/05 21:31:06 $</p> <div class="toc">&nbsp;Table of contents </div> <ul> <li><a href="#intro">Introduction<a> <li><a href="#output">Ouput</a> <li><a href="#source">PHP source syntax highlight<a> <li><a href="#run">Play demo<a> </ul> <a name="intro"> <h2><img src="../images/info.gif"/> Introduction</h2> <p>This example requires : <ul> <li>PEAR::HTML_Progress 1.2.0RC3 or better.</li> <li>PEAR::Log 1.8.0 or better.</li> </ul> </p> <hr/> <p><b>This example will show you how to customize errors logs renderer.</b></p> <p>An error was volontary made on call of <b>setAnimSpeed()</b> method. By default if you don't specify any logger, a <b>display</b> driver will be added with options below: <ul> <li>default context callback: PEAR_ErrorStack::getFileLine() <li>message callback: HTML_Progress::_msgCallback() <li>error callback: HTML_Progress::_handleError() </ul> <p>To set any logger, it should be defined as an array and given as the last parameter of HTML_Progress class constructor.</p> <p>Array format : <pre> array( 'display_errors' = 'on' | 'off', 'log_errors' = 'on' | 'off', 'pushCallback' = valid callback for PEAR_ErrorStack, 'msgCallback' = valid callback for PEAR_ErrorStack, 'contextCallback' = valid callback for PEAR_ErrorStack 'handler' => array( PEAR::Log driverName => array( 'name' => PEAR::Log driver name 'ident' => PEAR::Log driver identification string 'conf' => array( PEAR::Log driver configure options ), 'level' => PEAR::Log driver error level ), ... ) </pre> </p> <h3>display_errors</h3> <p> Print out errors (as a part of the output). For production web sites, you're strongly encouraged to turn this feature off, and use error logging instead. Keeping display_errors enabled on a production web site may reveal security information to end users, such as file paths on your Web server, your database schema or other information. </p> <h3>log_errors</h3> <p> Log errors into a log file (server-specific log, stderr, syslog ...) As stated above, you're strongly advised to use error logging in place of error displaying on production web sites. </p> <p>So, if you want to turn OFF all output errors, then you may write:</p> <table class="hl-table" width="100%"> <tr> <td class="hl-main" valign="top"> <span class="hl-inlinetags">&lt;?php </span><br/> <span class="hl-reserved">require_once </span><span class="hl-quotes">'</span><span class="hl-string">HTML/Progress.php</span><span class="hl-quotes">'</span><span class="hl-code">;</span><br/> <span class="hl-var">$logger</span><span class="hl-code"> = </span><span class="hl-reserved">array</span><span class="hl-brackets">()</span><span class="hl-code">;</span><br/> <span class="hl-var">$logger</span><span class="hl-brackets">[</span><span class="hl-quotes">'</span><span class="hl-string">display_errors</span><span class="hl-quotes">'</span><span class="hl-brackets">]</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">off</span><span class="hl-quotes">'</span><span class="hl-code">; </span><span class="hl-comment">// turn off browser screen output</span><br/> <span class="hl-var">$logger</span><span class="hl-brackets">[</span><span class="hl-quotes">'</span><span class="hl-string">log_errors</span><span class="hl-quotes">'</span><span class="hl-brackets">]</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">off</span><span class="hl-quotes">'</span><span class="hl-code">; </span><span class="hl-comment">// turn off all PEAR::Log drivers output</span><br/> <span class="hl-var">$bar</span><span class="hl-code"> = </span><span class="hl-reserved">new </span><span class="hl-identifier">HTML_Progress</span><span class="hl-brackets">(</span><span class="hl-var">$logger</span><span class="hl-brackets">)</span><span class="hl-code">;</span><br/> <span class="hl-inlinetags">?&gt;</span> </td> </tr> </table> <h3>LOG::display handlers</h3> <p> <b>I would have a PEAR_ErrorStack structure with context in bold face or any other render.</b> <br/> But the display driver in PEAR::Log 1.8.4 package can't allow it. So i've decided to make a patch. Here are both versions :</p> <ul> <li><a target="_blank" href="../highlighter.php?file=errorstack/display184.php">Original</a> display handler. <li><a target="_blank" href="../highlighter.php?file=errorstack/display2.php">My version</a> of display handler. </ul> </p> <p>[<a href="#top">Top</a>]</p> <a name="output"> <h2><img src="../images/image.gif"/>&nbsp;Output</h2> <h3>Browser </h3> <p><font size="1"> <b>Critical </b>: invalid input, parameter #1 "$delay" was expecting "integer", instead got "string" <br/><font color="blue"> [class="html_progress" method="setanimspeed" file="E:\EasyPHP\php\PEAR\HTML\Progress.php" line="874"] </font> </font></p> <p>[<a href="#top">Top</a>]</p> <a name="source"> <h2><img src="../images/source.gif"/>&nbsp;PHP source syntax highlight</h2> <a target="_blank" href="../highlighter.php?file=errorstack/display_errors.php">Open</a> source listing in a new window. <p>[<a href="#top">Top</a>]</p> <a name="run"> <h2><img src="../images/run.gif"/>&nbsp;Play demo</h2> <p><a href="display_errors.php?push=0">Run</a> the script and die on exception.</p> <p><a href="display_errors.php?push=1">Run</a> the script and catch exception.</p> <p>[<a href="#top">Top</a>]</p> </body> </html> http://cvs.php.net/co.php/pear/HTML_Progress/examples/errorstack/display_errors.php?r=1.1&p=1 Index: pear/HTML_Progress/examples/errorstack/display_errors.php +++ pear/HTML_Progress/examples/errorstack/display_errors.php <?php @include '../include_path.php'; /** * Natural Horizontal ProgressBar example with blue skin. * Display errors only on browser screen with full context * * @version $Id: display_errors.php,v 1.1 2004/07/05 21:31:06 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress */ require_once 'HTML/Progress.php'; function _pushCallback($err) { // don't die if the error is an exception (as default callback) } $logger = array(); if ($_GET['push']) { $logger['pushCallback'] = '_pushCallback'; // don't die when an exception is thrown $logger['display_errors'] = 'off'; // turn off browser screen output } $logger['handler']['display'] = array( 'conf' => array( 'printf' => '<b>%s</b>: %s <br/>' . '<font color="blue">' . '[class="%s" method="%s" file="%s" line="%s"]' . '</font>', 'ereg' => 'in (.*)::(.*) \(file (.*) at line (.*)\)' ) ); $bar = new HTML_Progress($logger); $bar->setAnimSpeed('100'); // < - - - will generate an API error if ($bar->hasErrors()) { $err = $bar->getError(); echo '<pre>'; print_r($err); echo '</pre>'; die('<h1>Catch PEAR_ErrorStack Exception error </h1>'); } ?> <html> <head> <title>FileLogger Progress example</title> <style type="text/css"> <!-- <?php echo $bar->getStyle(); ?> body { background-color: #EEEEEE; color: #000000; font-family: Verdana, Arial; } a:visited, a:active, a:link { color: navy; } // --> </style> <script type="text/javascript"> <!-- <?php echo $bar->getScript(); ?> //--> </script> </head> <body> <h1><?php echo basename(__FILE__); ?></h1> <?php echo $bar->toHtml(); $bar->run(); ?> <p>&lt;&lt; <a href="../index.html">Back examples TOC</a></p> </body> </html> http://cvs.php.net/co.php/pear/HTML_Progress/examples/errorstack/log_errors.html?r=1.1&p=1 Index: pear/HTML_Progress/examples/errorstack/log_errors.html +++ pear/HTML_Progress/examples/errorstack/log_errors.html <!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 name="robots" content="index,nofollow" /> <meta name="keywords" content"="HTML_Progress, PEAR_ErrorStack, API error, progress meter" /> <meta name="description" content="all API HTML_Progress errors are logs on File" /> <meta name="author" content="Laurent Laville" /> <title>PEAR::HTML::Progress example: ErrorStack on File</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="../examples.css" /> </head> <body> <a name="top"> <p><a href="../index.html"><img src="../images/home.gif" alt="Examples TOC"/>examples</a></p> <h1><span class="chapter">File </span></h1> <p align="right">$Date: 2004/07/05 21:31:06 $</p> <div class="toc">&nbsp;Table of contents </div> <ul> <li><a href="#intro">Introduction<a> <li><a href="#output">Ouput</a> <li><a href="#source">PHP source syntax highlight<a> <li><a href="#run">Play demo<a> </ul> <a name="intro"> <h2><img src="../images/info.gif"/> Introduction</h2> <p>This example requires : <ul> <li>PEAR::HTML_Progress 1.2.0RC3 or better.</li> <li>PEAR::Log 1.8.0 or better.</li> </ul> </p> <hr/> <p><b>This example will show you how to customize errors logs renderer.</b></p> <p>An error was volontary made on call of <b>setAnimSpeed()</b> method. By default if you don't specify any logger, a <b>display</b> driver will be added with options below: <ul> <li>default context callback: PEAR_ErrorStack::getFileLine() <li>message callback: HTML_Progress::_msgCallback() <li>error callback: HTML_Progress::_handleError() </ul> <p>To set any logger, it should be defined as an array and given as the last parameter of HTML_Progress class constructor.</p> <p>Array format : <pre> array( 'display_errors' = 'on' | 'off', 'log_errors' = 'on' | 'off', 'pushCallback' = valid callback for PEAR_ErrorStack, 'msgCallback' = valid callback for PEAR_ErrorStack, 'contextCallback' = valid callback for PEAR_ErrorStack 'handler' => array( PEAR::Log driverName => array( 'name' => PEAR::Log driver name 'ident' => PEAR::Log driver identification string 'conf' => array( PEAR::Log driver configure options ), 'level' => PEAR::Log driver error level ), ... ) </pre> </p> <h3>display_errors</h3> <p> Print out errors (as a part of the output). For production web sites, you're strongly encouraged to turn this feature off, and use error logging instead. Keeping display_errors enabled on a production web site may reveal security information to end users, such as file paths on your Web server, your database schema or other information. </p> <h3>log_errors</h3> <p> Log errors into a log file (server-specific log, stderr, syslog ...) As stated above, you're strongly advised to use error logging in place of error displaying on production web sites. </p> <p>So, if you want to turn OFF all output errors, then you may write:</p> <table class="hl-table" width="100%"> <tr> <td class="hl-main" valign="top"> <span class="hl-inlinetags">&lt;?php </span><br/> <span class="hl-reserved">require_once </span><span class="hl-quotes">'</span><span class="hl-string">HTML/Progress.php</span><span class="hl-quotes">'</span><span class="hl-code">;</span><br/> <span class="hl-var">$logger</span><span class="hl-code"> = </span><span class="hl-reserved">array</span><span class="hl-brackets">()</span><span class="hl-code">;</span><br/> <span class="hl-var">$logger</span><span class="hl-brackets">[</span><span class="hl-quotes">'</span><span class="hl-string">display_errors</span><span class="hl-quotes">'</span><span class="hl-brackets">]</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">off</span><span class="hl-quotes">'</span><span class="hl-code">; </span><span class="hl-comment">// turn off browser screen output</span><br/> <span class="hl-var">$logger</span><span class="hl-brackets">[</span><span class="hl-quotes">'</span><span class="hl-string">log_errors</span><span class="hl-quotes">'</span><span class="hl-brackets">]</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">off</span><span class="hl-quotes">'</span><span class="hl-code">; </span><span class="hl-comment">// turn off all PEAR::Log drivers output</span><br/> <span class="hl-var">$bar</span><span class="hl-code"> = </span><span class="hl-reserved">new </span><span class="hl-identifier">HTML_Progress</span><span class="hl-brackets">(</span><span class="hl-var">$logger</span><span class="hl-brackets">)</span><span class="hl-code">;</span><br/> <span class="hl-inlinetags">?&gt;</span> </td> </tr> </table> <h3>LOG::display handlers</h3> <p> <b>I would have a PEAR_ErrorStack structure with context in bold face or any other render.</b> <br/> But the display driver in PEAR::Log 1.8.4 package can't allow it. So i've decided to make a patch. Here are both versions :</p> <ul> <li><a target="_blank" href="../highlighter.php?file=errorstack/display184.php">Original</a> display handler. <li><a target="_blank" href="../highlighter.php?file=errorstack/display2.php">My version</a> of display handler. </ul> </p> <p>[<a href="#top">Top</a>]</p> <a name="output"> <h2><img src="../images/image.gif"/>&nbsp;Output</h2> <h3>Browser </h3> <p><font size="1"> <b>Error </b>: invalid input, parameter #1 "$delay" was expecting "less or equal 1000", instead got "10000" in <b>html_progress::setanimspeed</b> </font></p> <h3>File </h3> <p><font size="1"> Jul 05 21:32:34 127.0.0.1 [error] invalid input, parameter #1 "$delay" was expecting "less or equal 1000", instead got "10000" in html_progress::setanimspeed (file E:\EasyPHP\php\PEAR\HTML\Progress.php at line 898) </font></p> <p>[<a href="#top">Top</a>]</p> <a name="source"> <h2><img src="../images/source.gif"/>&nbsp;PHP source syntax highlight</h2> <a target="_blank" href="../highlighter.php?file=errorstack/log_errors.php">Open</a> source listing in a new window. <p>[<a href="#top">Top</a>]</p> <a name="run"> <h2><img src="../images/run.gif"/>&nbsp;Play demo</h2> <p><a href="log_errors.php">Run</a> the script.</p> </body> </html> http://cvs.php.net/co.php/pear/HTML_Progress/examples/errorstack/log_errors.php?r=1.1&p=1 Index: pear/HTML_Progress/examples/errorstack/log_errors.php +++ pear/HTML_Progress/examples/errorstack/log_errors.php <?php @include '../include_path.php'; /** * Natural Horizontal ProgressBar example with blue skin. * Logs errors on file (with full context) * and browser display (restricted context) * * @version $Id: log_errors.php,v 1.1 2004/07/05 21:31:06 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress */ require_once 'HTML/Progress.php'; function _pushCallback($err) { // don't die if the error is an exception (as default callback) } $logger = array(); $logger['handler']['file'] = array( 'name' => 'progress.log', 'ident' => $_SERVER['REMOTE_ADDR'] ); /* only class-method context will be display on message error of browser screen but full context will be written in file logger Recommanded for production WebSite */ $logger['handler']['display'] = array( 'conf' => array( 'printf' => '<b>%s </b>: %s in <b>%s</b>', 'ereg' => 'in (.*) \(file (.*) at line (.*)\)' ) ); $bar = new HTML_Progress($logger); $bar->setAnimSpeed(10000); if ($bar->hasErrors()) { exit; } ?> <html> <head> <title>FileLogger Progress example</title> <style type="text/css"> <!-- <?php echo $bar->getStyle(); ?> body { background-color: #EEEEEE; color: #000000; font-family: Verdana, Arial; } a:visited, a:active, a:link { color: navy; } // --> </style> <script type="text/javascript"> <!-- <?php echo $bar->getScript(); ?> //--> </script> </head> <body> <h1><?php echo basename(__FILE__); ?></h1> <?php echo $bar->toHtml(); $bar->run(); ?> <p>&lt;&lt; <a href="../index.html">Back examples TOC</a></p> </body> </html>
« previous php.pear.cvs (#21546) next »