Created
October 1, 2013 13:49
-
-
Save nerones/6778719 to your computer and use it in GitHub Desktop.
Revisions
-
nerones created this gist
Oct 1, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,59 @@ class LoggerHook { private $CI; function __construct() { $this->CI =& get_instance(); } public function log() { $logger = new Logger('my_logger'); $logger->pushHandler(new MongoDBHandler(new \MongoClient(), 'test', 'test')); if (isset($this->CI->session)) { $session_data = $this->CI->session->all_userdata(); } else { $session_data = 'No session defined'; } $dbs = array(); // Let's determine which databases are currently connected to foreach (get_object_vars($this->CI) as $CI_object) { if (is_object($CI_object) && is_subclass_of(get_class($CI_object), 'CI_DB') ) { $dbs[] = $CI_object; } } $queries = array(); if (count($dbs) > 0){ foreach ($dbs as $db){ $driver_name = get_class($db); if (count($db->queries) > 0){ foreach ($db->queries as $key => $val) { $time = number_format($db->query_times[$key], 4); $queries[$driver_name][] = array('time' => $time , 'query' => $val); } } } } else { $queries = 'There is no queries to log'; } $logger->addInfo( 'Session and queries', array( 'session' => $session_data, 'database' => $queries'url' => $this->CI->uri->uri_string() ) ); } }