-1

I am creating a PHP application and I want to display the number of times an error has occurred. The problem that I am trying to figure out is if an error has already been reported or if its new using the following values:

  1. Message (ie: Attempted to divide by zero.)
  2. Stack trace (ie: at componentNETapp.Form1.btnTrackExceptionsUn_Click(Object sender, EventArgs e) ...)
  3. Source (ie: componentNETapp)
  4. Target site (ie: Void btnTrackExceptionsUn_Click(System.Object, System.EventArgs))

Thanks

SameOldNick
  • 2,397
  • 24
  • 33
  • Are you wondering which data to use? To me, I usually just group them by file & line, the rest is often data-dependent. As long as you are not putting to much statements in 1 line that works. Anything else (failed x times with this kind of input, y times with that kind of input) is probably overdoing it and a lot of work, and only of interest when actually working do solve it, in which case you don't want to see them grouped anyway. – Wrikken Jan 28 '12 at 23:37
  • So would the source variable work? Or would it change everytime an error is reported to the server? – SameOldNick Jan 29 '12 at 02:06
  • Provide some example of code in here or at least what you have tried. I do not think somebody will write the whole code for you ... – Mike Jan 29 '12 at 11:28
  • So just to be clear again, I am not talking about exceptions from PHP. I am writing a application that is I guess what youd call "Runtime Intelligence" so whenever someone uses a software program it sends analytic data to my PHP application (such as feature usage, execution time, exceptions that occurred, etc). I want to know a good way to group the exceptions so I am able to see how many times each exception occurred and in what environment they are occurring. – SameOldNick Jan 31 '12 at 06:48

1 Answers1

3

First of all Errors or Exceptions? PHP differs between errors and exceptions. Generally the Error Handling and Logging­Docs section of the manual might be of interest.

For Errors:

error_get_last­Docs will return the last error with the following information: Type (integer), Message (string), File (string) and Line (integer). I would say this is self explanatory. You might also want to look into set_error_handler­Docs which will - next to these four bits of information - also offer you an error context you could make use of.

If you need more information about an error, there is also the backtrace in PHP debug_backtrace­Docs which can add even more context.

For Exceptions:

Each Exception­Docs has similar members: Message (string), Code (integer), File (string) and Line (integer). It also has a Trace which contains more information and could be used as context. It's also possible to set a previous exception to nest exceptions. Like the the error handler, it's possible to use an exception handler as well: set_exception_handler­Docs.


With the information given, you should be able to handle and log all errors/exceptions in a manner that you can analyse them later on. Next to that it's also possible to make use of PHP error logging and to store those errors into a database. See Outputting all PHP errors to database not error_log for a simple example. I would say the key point is that you store the error information in a more or less normalized form, so that you can define criteria later on how to count/group them.

If you're looking for more infrastructure, take a look into the apache logging services project that offers some tools (e.g. a viewer) and a PHP logger exists for it, too (log4php).

But this is just exemplary, other tools exist as well, some of them are using a MySQL backend and you can not only track PHP but also other errors.

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836
  • I am not talking about PHP errors/exceptions. I am talking about errors being reported from other languages (C++, C#, VB.NET, etc) and being able to group them together so I can see how many times the error is being reported and what type of environment (OS, CPU, RAM, etc) it is occurring in. – SameOldNick Jan 31 '12 at 06:37
  • Then you need to normalize the logs, store them in a central location and use a tool to process these. Something comparable to apache logging or the log inside the IDE and such. – hakre Jan 31 '12 at 11:35