1

I'm trying to disable displaying of errors in a file and just log them into a log file

<?php
error_reporting('E_ALL');
echo $x;
?>

The log file works when I remove the error_reporting('E_ALL') but then the errors are also displayed. Is there another way to do this, but disabling error reporting on specific pages only.

2 Answers 2

3

You can create a custom error handling function and set it via set_error_handler():

set_error_handler(function($errno, $errstr, $errfile = null, $errline = 0, $errcontext = null)
{
    // Append $errstr and other useful information to a file
    @file_put_contents('error_log', "ERROR: $errstr\n", FILE_APPEND);

    return true; // disable regular PHP error reporting
});
Sign up to request clarification or add additional context in comments.

Comments

2

See http://www.julianbez.com/blog/2006/02/19/how-to-set-up-error-logging-with-php/

Hope that helps...

1 Comment

I couldn't post the source code for this because of the license on the site.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.