Hello guys, hope you all had a happy new year.
So, my question is, what's the best way to make a log of actions. Let me explain it with a example, suppose we have these entities:
User
Friend
(User is a friend of another User, many to many relationship)
Message
(An user can message another user)
Group
(An user can be in various groups)
Game
(A game can be played with various players, has some info like date of the game. this results in two tales, games and games_users, the latter stores a relationship between user and a game)
Now, I wanted to make a log, for example:
User A (link to user) made a new friend, User B (link to user)
User A (link to user), B (link to user) and C (link to user) played a game (link to game)
User C (link to user) joined a group D (link to group)
So, I wanted to make a flexible log, that could store as many references as I wanted and references to different entities (user and game for example).
I know two ways of doing this, but they all have one or more problems:
When logging an action I directly store the pure text I want (i.e: only 1 char field, which would store 'User C joined a group'). But, there is a problem this way, this text needs to be translated to other languages and I can not have a field for each language.
Having a main table
log
, which each rows represent a log action and a code so I know which action is that, i.e: an user joined a group, x users played a game. I then have another table for each of the foreign key types needed, so I'd havelog_user
,log_group
andlog_game
For example,log_user
with a field referencinglog
and another referencinguser
. This way I can have multiple users for a same log action. Problems: rather complex and could result in substantial overhead as depending of the log action I'd have to query to multiple tables. Is this correct, would it be too cpu-intensive?
So, I'm open to new ideas and brainstorming. What's the best approach for this kind of problem? Thanks in advance, I hope I have explained it in a clear way. If there is any question, please ask.
Edit: I decided to start a bounty as I'm not really happy with the answers I have received. Will make any clarifications if needed. Thanks
I want something very similar to facebook/orkut/social networks "friend updates". This will be displayed to users.