PHP error logging - can I log the entire site error in one file?

in PHP.INI, I can set the variable "error_log" and it is currently set to "error_log" which manages one file of that name in each directory

Did you know ... if I set it to "public_html / error_log" - I only get one error log file? Any other way to do this? I just want one site-wide error file to be checked, not one in each subdirectory.

For bonus tags, can I send me an email every time a new entry is added to the file?

Left as an exercise for the reader - can I ignore some of the "mistakes" that are actually wrong?

+2


a source to share


4 answers


If you are using PHP under Apache, you can set php directives in a file .htaccess

, so for site or even directory see http://php.net/manual/en/configuration.changes.php



+1


a source


you can use set_error_handler

and set it to a function that writes it to a file (and ignores some types of errors if you are for example) and sends an email



function myErrorHandler($errno, $errstr, $errfile, $errline) {
  // check if we want to log the error
  // log the error
  // send the mail
}

set_error_handler('myErrorHandler');

      

+1


a source


I think the answer is yes, which should work.

In terms of email, knittl gave the correct answer, but there are risks. 1 - you may end up with an email flow, 2 - this may slow down the delivery of pages because some of the email sending methods in PHP take a few seconds to return control to the calling script, which is a problem if it hasn't sent its own yet results to the client.

If you would like to receive email notifications, you can consider an alternative approach such as. a script executed by cron that sends you an email if a log has been written since it was last run. This fixes both problems and you can control the maximum email speed by the frequency the script runs at.

+1


a source


Specifying an absolute path for error_log, e.g.

/var/logs/php.err

      

in php.ini will make this php error log file the default for the whole system. You can then do logging to the server / in the directory by placing the overridden error_log directives in the appropriate virtual host / directory settings (e.g. Apach Apache files, .htaccess, etc.) if you need to log specific areas differently.

0


a source







All Articles