What is the best practice for logging users activity?

Viewed 24126

I'd like to implement users' activity logging for my web app (php+js+mysql).

Previously, I've used this appoach:

  • on users login create a temporary table in the database to store users id
  • create triggers for all tables which insert row in activity table using users id from that temporary table

Now I don't really want to put so much logic in the database, so my question is: what is the best practice? Should I stay with the described method, or should I use something else?

Edit 1

I've seen this question, but I'm intrested in comparing the described method with one in the answers.

Edit 2

Why do I need logs: I need to know which user to blame if something goes wrong =)

Logs have to contain changed data and new data to see what has actually changed.

There won't be many users cause it's a corporate app and our company is not so large.

The main question is where should I put logging logics: database or application (php backend) level?

3 Answers

I'd really avoid adding another layer of logic on top of your current PHP+MySQL setup. Scaling that service will be hard as it is, the last thing you want to do is run queries on top of what you already go going to get different actions that a user took. I understand there won't be a ton of users, well, not right now they aren't but who can tell what will happen 12 or 24 months from now.

An easier way would be to log everything and then use a tool that aggregates those logs and manages that for you. Take sematext.com for example. They offer their logs app for free with some limitations but it should be plenty enough for you to understand if this is something that you can use or not.

Check out the little logs preview screen. All your log data is there, easy to read, and understand and they also have a pretty neat filtering and search option too.

Logs app in Sematext.com

Other similar tools are

  1. Datadoghq.com
  2. Logdna.com
  3. logz.io

Most of them come with a free tier or free trial so that you can give 'em a go before sticking with one as each tool will have their own fortes.

Related