CodeIgniter Forums
How to log actions? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: How to log actions? (/showthread.php?tid=74239)



How to log actions? - jellix - 09-01-2019

Hi,

I want to log data-modifications.
For that I could create a new realtionship table where I add a new entry with every SQL-Insert or Update action.

Every log should contain several infos like the user-id, the data-object that was modified, maybe the before and after-value and the action itself (create, update, delete).

Should I write a custom action for that within every controller-function that adds, updates or deletes data?
Or should I look for a hook to manage it?

Thanks in advance!

jellix


RE: How to log actions? - php_rocs - 09-01-2019

@jellix,

I don't know of any hooks that do everything you wish. This seems more like a custom action.


RE: How to log actions? - ignitedcms - 09-01-2019

Not sure about the before and after state but this might give you something to start with

https://stackoverflow.com/questions/39587940/logging-all-queries-after-execution-in-codeigniter


RE: How to log actions? - jellix - 09-01-2019

Thanks!

I‘m gonna write custom actions within my controller functions.


RE: How to log actions? - milengardev1994 - 09-01-2019

I would suggest to write your own logging function for each function in the controller.
I guess you also want to log specific input in the controller functions.


RE: How to log actions? - includebeer - 09-03-2019

In CI4 you can define callbacks to be executed before or after an insert, update or delete in you model: https://codeigniter4.github.io/userguide/models/model.html#model-events