Welcome Guest, Not a member yet? Register   Sign In
Logging user activities best practice.
#1

[eluser]Fierymind[/eluser]
Hi,

I'm finishing back-end software for some company using CI, backend mainly is multi-user multi-access-level software allow employees/admins to add/delete/edit reports, complaints, contact lists,..etc.

I want to include a raw audition-reel or activity log to the the software, so the admin can find which employee was last person accessed some record in some table ..etc


the only thing I can think about to complete this job, is create a model for logging, call the logging function from every function in every controller... but this is hard work, I have already tens of functions.

Is there another way to do that? Like using hooks? .. if I used hooks, can the running hook return the executed controller/function and the user name stored in session?

any feed back will be really helpful

Thank you
#2

[eluser]xwero[/eluser]
If you want a detailed record of everything there is no other way to call a logging function in every method.

CI has a logging function of its own that gets loaded by default. You could place all your logging messages on the info level when you call the log_message function.
#3

[eluser]Ignacio[/eluser]
I'm looking for something like Fierymind. Tracking all the users activities, like if the user make a comment, if the user make a new friend, if the user set an item as favorite, etc etc etc.

Any idea to build this?

Thanks!
#4

[eluser]Fierymind[/eluser]
for me, I solved this problem using a new model with function I called logthis($what_happen) .. I put the function in each each controller/function I want to log and store the activity in DB.

usually, you will pass some string in $what_happen .. like 'user login', 'item deleted' .. while the $logthis function can get the USER info (if any) direct from session, and can get client IP and current time, with some special event, I saved the whole $_POST in the db.

so overall its acceptable solution for me because I have project I want to finish .. BUT I think there is a better way .. like to get $what_happen value direct from Controller/Function names and run $logthis function using Hooks, so you get ANY activity logged without adding single line in controller... then you use a Config file to set filters in what functions to be logged or ignored.
#5

[eluser]Ignacio[/eluser]
Well, yes, you can use Hooks for storing all the activities, here is a good one: http://ellislab.com/forums/viewthread/91696/

But that is not doing the really thing I want, so I'm doing just like you, but I'm using id_user, id_target, target_type, and doing a join with all the types. I don't want to repost the same content in two tables.

Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB