How To Log All Query

Seme Framework still has missing feature for capturing all query statement that running by framework.

But, it is still possible for you to capture the query. Here is how to achieved that.

Create the log writer Class

First thing first we have to create a class that can write log into a file. Lets say we created the Seme_Log2 class on kero/lib/seme_log2.php, and the here is the source code.

<?php
class Seme_Log2 {
  var $directory = '';
  var $filename = 'seme.log';
  var $path = '';

  public function __construct(){
    $this->directory = SENEROOT;
    $this->path = $this->directory.DIRECTORY_SEPARATOR.$this->filename;
    if(!file_exists($this->path)) touch($this->path);
    if(!is_writable($this->path)){
      $this->directory = SENECACHE;
      $this->path = $this->directory.DIRECTORY_SEPARATOR.$this->filename;
      if(is_writable($this->path)) touch($this->path);
    }
  }
  public function changeFilename($filename){
    $this->filename = $filename;
    $this->directory = SENEROOT;
    $this->path = $this->directory.DIRECTORY_SEPARATOR.$this->filename;
    if(!file_exists($this->path)) touch($this->path);
    if(!is_writable($this->path)){
      $this->directory = SENECACHE;
      $this->path = $this->directory.DIRECTORY_SEPARATOR.$this->filename;
      if(is_writable($this->path)) touch($this->path);
    }
  }

  public function write($str){
    $f = fopen($this->path,'a+');
    fwrite($f,date("Y-m-d H:i:s").' - ');
    fwrite($f,$str.PHP_EOL);
    fclose($f);
  }
  public function getPath(){
    return $this->path;
  }
}
            

Override the Class Model

Open kero/sine/SENE_MySQLi_Engine.php and then add the following codes.

After exec method

Find method exec on kero/sine/SENE_MySQLi_Engine.php, and then add this code.

.
public function exec($sql){
.
if(!class_exists('Seme_Log2')) require_once(SENEROOT.'kero/lib/seme_log2.php');
$sl = new Seme_Log2();
$sl->changeFilename('sql.log');
$sl->write('SENE_MySQLi::exec -- '.$sql);
            

After query method

Find method exec on kero/sine/SENE_MySQLi_Engine.php, and then add this code.

.
.
public function query($sql,$cache_enabled=0,$flushcache=0,$type="object"){
            
if(!class_exists('Seme_Log2')) require_once(SENEROOT.'kero/lib/seme_log2.php');
$sl = new Seme_Log2();
$sl->changeFilename('sql.log');
$sl->write('SENE_MySQLi::exec -- '.$sql);
            

Conclusion

After modified the core library, we can view the query log through sql.log.