kevdoug Posted July 26, 2006 Share Posted July 26, 2006 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 filedefine ([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(); }}echoset_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);?> Quote Link to comment https://forums.phpfreaks.com/topic/15697-define-error-handling-directory/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.