Hooks are supported in CodeIgniter (more info here). Here's my hook class to perform the logging:
To enable hooks, you'll need to edit the config/hooks.php file. Here's the content of the file to enable the Logger class above:
class Logger {
private $CI;
public function __construct() {
$this->CI =& get_instance();
}
public function request_logger() {
$uri = $this->CI->uri->uri_string();
$params = trim(print_r($this->CI->input->post(), TRUE));
log_message('info', '==============');
log_message('info', 'URI: ' . $uri);
log_message('info', '--------------');
log_message('info', $params);
log_message('info', '==============');
}
}
$hook['post_controller_constructor'] = array(
'class' => 'Logger',
'function' => 'request_logger',
'filename' => 'Logger.php',
'filepath' => 'hooks'
);
I chose to use "post_controller_constructor" as it is called before any methods in the controller class is executed.
Output below shows how the output looks like from the application logs:
INFO - 2011-12-15 05:09:24 --> URI: services/promos/add_comment
INFO - 2011-12-15 05:09:24 --> Array
(
[param1] => value1
[id] => dj3243hasdgasdg
[msg] => Testing testing
)
0 comments:
Post a Comment