views:

132

answers:

3

It is painful to fish out things from apache error_log. Does anybody have pointers to some better error collection mechanism. Something like what is described in "Using FogBUGZ to Get Crash Reports From Users - Automatically!", but for a PHP/apache webapp

More specifically, some mechanism to hook the errors that is thrown by PHP to some bug tracking software. Maybe pointers to some library/code which captures the errors/warnings and collect the data which can be entered into the bug-tracking software. With the following bonus features:

  • identifies duplicate bugs.
  • if a bug leads to more than one error message, it should be captured as one bug
A: 

We're using Zend Platform on our servers. It's not free but works very well and does most of what you ask.

It allow your to define events and set triggers. When triggered the entire state of the application is logged. You can browse and filter graphs or lists of event types, mark events as duplicates, view source, etc.

The nicest thing is this: since the entire event is captures you can debug the event with a single click. The state of the application (code, session, variables, cookies, and even uploaded files) is sent to Eclipse and paused. You can then step through the code to see the exact state of the application when the bug occurred. Very useful for root cause analysis. If you want, you can replay the error on a development server, so you don't interfere with production.

Martijn Heemels
+1  A: 

You can specify your own custom PHP error handler. Here is a simple example below.

function log_error_handler($errno, $str, $file, $line) { switch($errno) { case E_USER_ERROR: add_log("PHP Error", "Error $errno on line $line in $file: $str", "fatal"); exit(1); break;

    case E_USER_WARNING:
        add_log("PHP Warning", "Warning $errno on line $line in $file: $str", "warning");
        break;

    case E_USER_NOTICE:
        add_log("PHP Notice", "Notice $errno on line $line in $file: $str", "note");
        break;

    default:

//uncomment this next line to catch // add_log("PHP", "Unknown error $errno on line $line in $file: $str", "note"); break; } } function add_log($code, $message, $type = 'message', $program = null ){ //do something like email the admin or enter in the data in to the bug tracking software db }

// ### function to log php errors #### set_error_handler("log_error_handler");

jebaird
A: 

Ignore the time of the error, and get an md5 hash of the error message. Check to see if that md5 hash is already in your database of errors. If not, add it. If it is, maybe you want to append the date it happened this time.

if a bug leads to more than one error message, it should be captured as one bug

That's tricky, unless you are very good with your use of error_log() function. You could just agree on a convention, such as:

error_log('ename:'.$error_name.' emessage:'.$e->toString());

That way you can parse out & group any errors with the same "ename" & md5 of "emessage".

lo_fye