tags:

views:

156

answers:

3

Hi

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?

+1  A: 

Off the top of my head, a couple of suggestions (if you haven't already implemented them)

  1. 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.

  2. 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.

karim79
1, 2 are done. Maybe I should leave it in that form for now, because I don't have better ideas :(
Fedyashev Nikita
Then you're done! As long as you can get what you need from the logs, and without too much effort, there probably aren't any major improvements to implement on your existing method.
karim79
Then your answer is marked as Accepted :)
Fedyashev Nikita
A: 

The de-facto standard for logging in the Java world for many years has been log4j. This has been ported to a number of other languages log4Net, log4Ruby and log4Php

I have never used log4php but if it implements the same patterns/algorithms as the other frameworks it will certainly do your job.

I will not claim that it's better than either of the options recommended by karim79 just that it follows a proven design.

Steve Weet
There is no release yet of log4php
Ólafur Waage
I worked with log4j earlier, but didn't have such task then. Either I don't know how to solve the problem with using of log4j. The question was not in this: What logging framework should I use? It's more like conceptual question
Fedyashev Nikita
+1  A: 

If you need to view all logs for a particular user session, use

session_start()

at the top of your script(s) and then prepend

session_id()

to the front of each log message.

adam
Nice idea, but unfortunately it has to be not for the whole user session, but for request(1 to 5 log messages at once).But your suggestion maybe useful in some case. Thank you, adam
Fedyashev Nikita