Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify Codeigniter profiler to send output to db instead of display on page

I'd like to use CI profiler as a tool to audit an app. However, obviously in this case, I do not want the output to be displayed on the page, but rather be logged to the db.

I was thinking I could hook into profiler grab the relevant details (query, uri_string, etc.) and send that to a table in the db.

I could extend the profiler class to send data to the db, but this doesn't eliminate the output to the screen. I'd like to be able to use the profiler normally as well from time to time, so re-writing the output class isn't desirable.

Any ideas appreciated.


What I ended up doing was creating a library and copylasagna Profiler.php into it to modify as needed.

like image 234
stormdrain Avatar asked Nov 15 '11 14:11

stormdrain


1 Answers

Try this. Add MY_Profiler.php to your libraries/ directory (I assume you're in the 2.0+ branch; if not, lemme know):

<?php
class MY_Profiler extends CI_Profiler {
    public function run()
    {
        $output = parent::run();
        // log output here, and optionally return it if you do want it to display
    }
}

EDIT: And to automatically enable the profiler for each controller (add to core/MY_Controller.php):

<?php
class MY_Controller extends CI_Controller {
    public function __construct()
    {
        parent::__construct();
        $this->output->enable_profiler(TRUE);
    }
}
// but each controller will have to extend MY_Controller, not CI_Controller...
class Somecontroller extends MY_Controller { //... }
like image 200
landons Avatar answered Sep 23 '22 23:09

landons