Jump to content

Recommended Posts

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 [color=red]define ('logfile', C:/log/logfile.txt(__FILE__) . '/logfile.txt');[/color] I have tried other ways but with no luck.

and here is the full script.

<?php

// Location of the error log file
define ([color=green]'logfile'[/color], dirname([color=purple]__FILE__[/color]) . [color=green]'/logfile.txt'[/color]);

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);

?>
Link to comment
https://forums.phpfreaks.com/topic/15697-define-error-handling-directory/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.