Examples TOCexamples

Error_Log handler - part 2.

$Date: 2004/08/07 14:28:59 $

 Table of contents

Introduction

This example requires :


This example will show you how to handle html_progress errors both for display and file logging system. Such as used in development phase.

An error was volontary made on call of setAnimSpeed method (line 20). As it's an API error, default is to return error after it was raised, so lines below line 21 will be executed.

Error is also logged on 'progress2.log' (line 8) flat file type (line 14) which format look like apache logs (lines 7 to 13).

display_errors

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.

1 <?php ini_set('display_errors', false); ?>

log_errors

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.

1 <?php ini_set('log_errors', true); ?>

 Render options

None, all default options are used. These options are :

Legend for lineFormat: Legend for contextFormat:

[Top]

 Output

Error: invalid input, parameter #1 "$delay" was expecting "less or equal 1000", instead got "10000" in html_progress::setanimspeed (file d:\php\pear\html_progress\examples\errorstack\secure\log_errors-p2.php at line 20)

Catch PEAR_Error

[pear_error: message="invalid input, parameter #1 "$delay" was expecting "less or equal 1000", instead got "10000"" code=-100 mode=return level=error prefix="" info="Array"]

Inside the progress2.log file:
127.0.0.1 [07/Aug/2004:14:04:36] - error - invalid input, parameter #1 "$delay" was expecting "less or equal 1000", instead got "10000" (context: Function="html_progress::setanimspeed" File="d:\php\pear\html_progress\examples\errorstack\secure\log_errors-p2.php" Line="20")

[Top]

 PHP source syntax highlight

  1. <?php
  2. require_once 'HTML/Progress.php';
  3.  
  4. ini_set('display_errors', true);  // in developement we may accept browser outputs
  5. ini_set('log_errors', true);      // be sure to logs errors
  6.  
  7. $options = array(
  8.     'destination' => 'progress2.log',
  9.     'extra_headers' => '',
  10.     'timeFormat' => '%d/%b/%Y:%H:%M:%S',
  11.     'lineFormat' => '%2$s [%1$s] - %3$s - %4$s (context: %5$s)',
  12.     'contextFormat' => 'Function="%3$s" File="%1$s" Line="%2$s"'
  13. );
  14. $logger['handler']['error_log'] = array('name' => HTML_PROGRESS_LOG_TYPE_FILE,
  15.                                         'ident' => $_SERVER['REMOTE_ADDR'],
  16.                                         'conf' => $options
  17.                                         );
  18.  
  19. $bar = new HTML_Progress($logger);
  20. $e = $bar->setAnimSpeed(10000);   // < - - - will generate an API error
  21.  
  22. if (is_object($e)) {
  23.     if (is_a($e,'PEAR_Error')) {
  24.         die('<h1>Catch PEAR_Error</h1>'.$e->toString());
  25.     }
  26. }
  27. ?>

[Top]