Jump to content


Photo

define error handling directory.


  • Please log in to reply
No replies to this topic

#1 kevdoug

kevdoug
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 26 July 2006 - 02:52 PM

Hi I've got this error handling script but I am unsure how to define the directory for the log here is the full path where I have the logfile.txt  C:/log/logfile.txt I have tried define ('logfile', C:/log/logfile.txt(__FILE__) . '/logfile.txt'); I have tried other ways but with no luck.

and here is the full script.

<?php

// Location of the error log file
define ('logfile', dirname(__FILE__) . '/logfile.txt');

function handle_errors($errlevel, $errstr, $errfile='', $errline='', $errcontext='') {
  $errstr = htmlentities($errstr);
  $error = '[' . date('d/m/Y H:i:s') . '] ';

switch ($errlevel) {
  case E_USER_ERROR:
  $error .= "ERROR: ";

  echo 'Sorry, something unexpected happen, and it has been logged for further investigation. Please go back where you came from. Thank you for your understanding.';
  $die = true;
  break;
  case E_USER_WARNING:
  case E_WARNING:
  $error .= "WARNING: ";
  break;
  case E_USER_NOTICE:
  case E_NOTICE:
  $error .= "NOTICE: ";
  break;
  default:
  $error .= "UNKNOWN: ";
  break;
  }

  $error .= " $errstr in line $errline of file $errfile\n";

  // Log error
  $f = fopen(logfile, 'a');
  fwrite($f, $error);
  fclose($f);

  // Error -> stop script execution?
  if (isset($die) AND $die == true) {
          die();
  }
}

echo

set_error_handler('handle_errors');

// Throws a notice
$a = $b;

// Throws a warning:
$f = fopen('bla');

// Throws a user notice:
trigger_error ('Something went wrong!',  E_USER_NOTICE);

// Throws a user warning:
trigger_error ('Something went REALLY wrong!', E_USER_WARNING);

// Throws a user error:
trigger_error ('It\'s completely broken!', E_USER_ERROR);

?>




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users