Examples TOCexamples TOC

File logger

$Date: 2004/04/18 13:25:43 $

 Table of contents

Introduction

This example will show you how errors could be logged.

An error was volontary made on call of setAnimSpeed() method. By default if you don't specify any logger, a display driver will be added with options below:

To set any logger, it should be defined as an array and given as the last parameter of HTML_Progress class constructor.

Array format :

  array(
   'display_errors' = 'on' | 'off',
   'log_errors' = 'on' | 'off',
   '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
                      ),
                  ...
  )

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.

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.

So, if you want to turn OFF all output errors, then you may write:


<?php 
require_once 'HTML/Progress.php';

$logger = array();
$logger['display_errors'] = 'off';     // turn off browser screen output
$logger['log_errors'] = 'off';         // turn off all PEAR::Log drivers output

$bar = new HTML_Progress($logger);
...
?>


[Top]

 PHP script

Set the PEAR::Log File driver and its config options


<?php 
require_once 'HTML/Progress.php';

$logger = array();
$logger['handler']['file'] = array(
    'name' => 'progress.log',
    'ident' => $_SERVER['REMOTE_ADDR']
);

$bar = new HTML_Progress($logger);
...
?>


[Top]

 Output

Browser

Critical : invalid input, parameter #1 "$delay" was expecting "integer", instead got "string" in html_progress::setanimspeed

File

Apr 03 12:32:09 127.0.0.1 [critical] invalid input, parameter #1 "$delay" was expecting "integer", instead got "string" in html_progress::setanimspeed (file E:\EasyPHP\php\PEAR\HTML\Progress.php at line 874)

[Top]

 Full example


<?php 
require_once 'HTML/Progress.php';

$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('100');
?>
<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;
}
// -->
</style>
<script type="text/javascript">
<!--
<?php echo $bar->getScript(); ?>
//-->
</script>
</head>
<body>

<?php 
echo $bar->toHtml(); 

do {
    $bar->display();
    if ($bar->getPercentComplete() == 1) {
        break;   // the progress bar has reached 100%
    }
    $bar->incValue();
} while(1);
?>

</body>
</html>
href:  ./log_errors.php

[Top]