PHP Error logging

Gosman
Gosman used Ask the Experts™
on
Is the a way of implementing a custom php error log for a particular script?

Eaxmple.

If I had a script called script.php I want to create an error log at /var/www/mydomain/script.log that only logs php errors from script.php
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
If you have PHP installed as Apache module, you can achieve that using .htaccess directive in conjunction with <Files>:

There is also a good article here..

http://faq.1and1.com/miscellaneous/14.html
<Files something.php>
    php_flag log_errors on
    php_value error_log /path/to/your/error.log
</Files>

<Files something_else.php>
    php_flag log_errors on
    php_value error_log /path/to/your/other_error.log
</Files>

Open in new window

Commented:
Towards the bottom of THIS PAGE, there is an excellent tutorial and examples on how to setup custom errorlog function using set_error_handler() in PHP.
Commented:
You can also create a custom error handler function.

See the attached example
You can also create a custom error handler function:

function exceptions_error_handler($severity, $message, $filename, $lineno) {
        if (error_reporting() == 0)     {
                return;
        }
        if (error_reporting() & $severity) {
                //Error reporting code goes here i.e.:
                throw new ErrorException($message, 0, $severity, $filename, $lineno);
        }
}
set_error_handler('exceptions_error_handler');

Open in new window

Commented:
was my suggestion helpful?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial