Adding a 'Footprint' log - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Adding a 'Footprint' log (/showthread.php?tid=4114) |
Adding a 'Footprint' log - El Forum - 11-07-2007 [eluser]Gavin Vickery[/eluser] I've been working on a client system where they want certain details, such as logins, logouts and system changes to be logged. I was using the 'INFO' (4) threshold setting for the CI native log function, but noticed that it will also log any threshold less than whats set. So if you have a log threshold of 3, 1, 2 and 3 will be logged. Since the client only wants 'Footprints' logged, I decided to tweak the Log library for CodeIgniter to only show this specific log type when used, instead of displaying them all. The type I set it to is 'FOOTPRINT' (5) Here are the steps to do it: Step 1: Mod the CI Log Library In the Log.php file located in the libraries directory change the line: Code: var $_levels = array('ERROR' => '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4'); Code: var $_levels = array('ERROR' => '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4', 'FOOTPRINT' => '5'); Then replace your write_log function with: Code: function write_log($level = 'error', $msg, $php_error = FALSE) Basically, we are just adding in: Code: // EDIT TO SHOW ONLY FOOTPRINT This just tells the function to log only 'FOOTPRINTS' when the Footprints threshold is set. That way we aren't effecting how CI core logging functionality works. Step 2: Set the Threshold Set the following line in the config.php file: Code: $config['log_threshold'] = 5; Step 3: Loggin Footprints Now you can log footprints just like any other log type in CI Code: log_message('footprint', 'User, John Doe, logged in successfully'); I'm not sure if anybody else could use this, but I figured I would post it anyway. Adding a 'Footprint' log - El Forum - 11-07-2007 [eluser]Derek Allard[/eluser] Great, thanks for contributing. No need to hack the install though, just save your changes in an applications/libraries folder, and CI will preferentially use your library over its own. Then, when you upgrade you won't need to re-hack anything. Adding a 'Footprint' log - El Forum - 11-07-2007 [eluser]Gavin Vickery[/eluser] Thanks Derek! I'll do that. Adding a 'Footprint' log - El Forum - 11-19-2007 [eluser]abmcr[/eluser] Thank you... very useful for me Adding a 'Footprint' log - El Forum - 11-19-2007 [eluser]pwninja[/eluser] Heh, I was about to do that this morning, thanks! Adding a 'Footprint' log - El Forum - 11-19-2007 [eluser]Gavin Vickery[/eluser] No problem abmcr and pwninja, glad you could get some use out of it. |