As mentioned by Patrick Savalle, you should use hooks. Use the post_controller_constructor hook so you can use all other CI materials.
1) In ./application/config/config.php set $config['enable_hooks'] = TRUE
2) In ./application/config/hooks.php add the following hook
$hook['post_controller_constructor'] = array( 'class' => 'Http_request_logger', 'function' => 'log_all', 'filename' => 'http_request_logger.php', 'filepath' => 'hooks', 'params' => array() );
3) Create a ./application/hooks/http_request_logger.php file and add the following code as an example.
if (!defined('BASEPATH')) exit('No direct script access allowed'); class Http_request_logger { public function log_all() { $CI = & get_instance(); log_message('info', 'GET --> ' . var_export($CI->input->get(null), true)); log_message('info', 'POST --> ' . var_export($CI->input->post(null), true)); log_message('info', '$_SERVER -->' . var_export($_SERVER, true)); } }
I tested it and it works for me (make sure logging is activated in your configuration file).
source share