Discussions

Web tier: servlets, JSP, Web frameworks: How to log user actions? (what's the usual way?)

  1. How to log user actions? (what's the usual way?) (3 messages)

    I'm making a medium scale web application and my boss wanted the user action to be logged, the information needed about the user action includes user's id, timestamp of the action, and other specific info about the action.

    Something like:

    Jon generated an invoice at 12:30 (invoice number 012938)
    Bill cancelled an order at 14:21 (order number 328273)

    In the previous version of out system, I logged these information in database, which increases lots of tables, cos I have to make a table for each different actions.

    I think that's probably not the right way to do it, so I'm considering of using log4j, I could attach each user action to a unique logger, and just log them into text files, will that be the right solution?

    I'm just wondering what's the usual way to log those kind of thing.

    Any comments would help, thanks.
  2. any comments please[ Go to top ]

    Need some comments, thanks a lot!
  3. any comments please[ Go to top ]

    Need some comments, thanks a lot!

    Auditing is easily handled by AOP in my opinion. Take a lot at Spring-AOP or AspectJ auditable samples.
  4. I would still go with the DB table sollution as you will need to query that later by various criteria.

    Why would you use different DB tables for different actions?
    You can always define a [UserAction] model in which you would store information like: [action type], [username], [url], [timestamp], [action description], [client_ip] etc...

    To feed this table you'd build your own Logger and call it from your controller. OR, a more clean solllution is to build a Valve (extend ValveBase) and use it without cluttering your code with logging calls.