Page 1 of 1

Re: Log PHP Error Messages

Posted: Sat Dec 25, 2010 3:36 am
by Darhazer
Setup custom error handler and log the IP - http://php.net/set_error_handler

Re: Log PHP Error Messages

Posted: Tue Dec 28, 2010 3:07 am
by jarofgreen
Sorry if this is a bit more complex than you want, but I'm working on a ticket system which has a module that collects full error reports including IP and environmental variables.
http://sourceforge.net/news/?group_id=317819&id=293422
The project is http://elastik.sourceforge.net/

Re: Log PHP Error Messages

Posted: Wed Dec 29, 2010 5:48 am
by Darhazer
Waterburn wrote:Darhazer, thanks for your reply. But setting up a custom error handle is a bit too much for me as a beginner. Is is possible to do this an easier way?
It's not hard:

Code: Select all

function myErrorHandler($errno, $errstr, $errfile, $errline)
{
    if (!(error_reporting() & $errno)) {
        // This error code is not included in error_reporting
        return false;
    }
    $filename = 'errors.log';
    $msg = '['.$_SERVER['REMOTE_ADDR'].']';
    $msg .= $errstr ' at ' . $errfile.':'$errline;
    file_put_contents($filename, $msg, FILE_APPEND);
    return true;
}
set_error_handler('myErrorHandler');