..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Log PHP Error Messages

Post by Darhazer »

Setup custom error handler and log the IP - http://php.net/set_error_handler
jarofgreen
Forum Commoner
Posts: 71
Joined: Sun Jul 11, 2010 12:40 pm

Re: Log PHP Error Messages

Post 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/
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Log PHP Error Messages

Post 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');
Post Reply