Skip to content

Instantly share code, notes, and snippets.

@Oxicode
Last active August 29, 2015 14:05
Show Gist options
  • Save Oxicode/0141d68c066c5ebacd71 to your computer and use it in GitHub Desktop.
Save Oxicode/0141d68c066c5ebacd71 to your computer and use it in GitHub Desktop.
public function afterFilter(){
parent::afterFilter();
if (class_exists('ConnectionManager') && class_exists('ChromePhp') && Configure::read('debug') > 1) :
$logs = ConnectionManager::getDataSource('default');
$this->Oxicode->logs_console($this->request->here, array_reverse($logs->getLog()));
endif;
}
public function logs_console($ubicacion = null, $logInfo = array()) {
if(count($logInfo['log']) === 0)
return ChromePhp::log($ubicacion . " No tiene querys");
ChromePhp::groupCollapsed($ubicacion . sprintf(' -- %s %s tomo %s ms', count($logInfo['log']), 'Query', $logInfo['time']));
foreach ($logInfo['log'] as $k => $i) :
$i += array('error' => '');
if (!empty($i['params']) && is_array($i['params'])) {
$bindParam = $bindType = null;
if (preg_match('/.+ :.+/', $i['query'])) {
$bindType = true;
}
foreach ($i['params'] as $bindKey => $bindVal) {
if ($bindType === true) {
$bindParam .= h($bindKey) ." => " . h($bindVal) . ", ";
} else {
$bindParam .= h($bindVal) . ", ";
}
}
$i['query'] .= " , params[ " . rtrim($bindParam, ', ') . " ]";
}
$error = !empty($i['error']) ? "\nError: ".$i['error']:"\n";
$logStr = $i['query'].$error."\nAfectado: ".$i['affected']."\nNum. Filas: ".$i['numRows']."\nTook(ms): ".$i['took']."\n\n";
if (!empty($i['error'])) {
ChromePhp::error($logStr);
} else if($i['took'] >= 100) {
ChromePhp::warn($logStr);
} else {
ChromePhp::info($logStr);
}
endforeach;
ChromePhp::groupEnd();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment