mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-07-13 00:12:43 -04:00
Add hook for database query logging - enable in config.php - (#924)
This commit is contained in:
@@ -33,6 +33,16 @@ $config['commit_sha1'] = '$Id$';
|
||||
*/
|
||||
$config['ospos_xss_clean'] = TRUE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Enable database query logging hook
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Logs are stored in application/logs
|
||||
|
|
||||
*/
|
||||
$config['db_log_enabled'] = FALSE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Base Site URL
|
||||
@@ -544,4 +554,4 @@ $config['rewrite_short_tags'] = FALSE;
|
||||
| Comma-separated: '10.0.1.200,192.168.5.0/24'
|
||||
| Array: array('10.0.1.200', '192.168.5.0/24')
|
||||
*/
|
||||
$config['proxy_ips'] = '';
|
||||
$config['proxy_ips'] = '';
|
||||
@@ -25,3 +25,10 @@ $hook['post_controller_constructor'][] = array(
|
||||
'filepath' => 'hooks'
|
||||
);
|
||||
|
||||
// 'post_controller' indicated execution of hooks after controller is finished
|
||||
$hook['post_controller'] = array(
|
||||
'class' => '',
|
||||
'function' => 'db_log_queries',
|
||||
'filename' => 'db_log.php',
|
||||
'filepath' => 'hooks'
|
||||
);
|
||||
29
application/hooks/db_log.php
Normal file
29
application/hooks/db_log.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
// Name of function same as mentioned in Hooks Config
|
||||
function db_log_queries()
|
||||
{
|
||||
$CI = & get_instance();
|
||||
|
||||
// check if database logging is enabled (see config/config.php)
|
||||
if($CI->config->item('db_log_enabled'))
|
||||
{
|
||||
// Creating Query Log file with today's date in application/logs folder
|
||||
$filepath = APPPATH . 'logs/Query-log-' . date('Y-m-d') . '.log';
|
||||
// Opening file with pointer at the end of the file
|
||||
$handle = fopen($filepath, "a+");
|
||||
|
||||
// Get execution time of all the queries executed by controller
|
||||
$times = $CI->db->query_times;
|
||||
foreach ($CI->db->queries as $key => $query)
|
||||
{
|
||||
// Generating SQL file alongwith execution time
|
||||
$sql = $query . " \n Execution Time:" . $times[$key];
|
||||
// Writing it in the log file
|
||||
fwrite($handle, $sql . "\n\n");
|
||||
}
|
||||
|
||||
// Close the file
|
||||
fclose($handle);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -54,3 +54,5 @@ function load_stats()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -9,7 +9,7 @@ class Item extends CI_Model
|
||||
if (ctype_digit($item_id))
|
||||
{
|
||||
$this->db->from('items');
|
||||
$this->db->where('item_id', (int)$item_id);
|
||||
$this->db->where('item_id', (int) $item_id);
|
||||
if ($ignore_deleted == FALSE)
|
||||
{
|
||||
$this->db->where('deleted', $deleted);
|
||||
|
||||
Reference in New Issue
Block a user