Recently I’ve faced such problem. I’m working on the application, in which logging is very important.
By logs in that application I mean the messages, like
- User A(id=x) has created invoice(invoice # is XXX) (1)
- User B(id=y) has purchased the book (2)
- User A(id=x) has approved invoice XXX (3)
(1) and (3) are messages of one particular request/command – so when I want to see the logs, I need to get all the information about this request log thread.
Because of the application is highly loaded and uses AJAX a lot, log message of different users/operations/requests can be mixed.
Temporary, I’ve fixed this problem like this:
I’ve created at the beginning of the request some unique UUID code, and prepend any log messages with this unique code. So, I can find all the messages of particular thread by simple grep UNIX command.
That solves the problem, but I’m not sure it is the best solution for the task. Looks more like reinventing the wheel. What solutions would you reccomend for this problem?
Off the top of my head, a couple of suggestions (if you haven’t already implemented them)
Log each different type of event into a separate log file, e.g. BookPurchases.log, InvoiceApprovals.log. That said keep a raw output log of everything in case it’s the sequence of events that matters as opposed to the classification.
Use a logging package if you don’t already have one, examples are The Log Package, or Zend_Log where you can have different logging priorities.
I don’t know if that’s of any use to you, as what you have said seems pretty solid.