Last active
August 29, 2015 14:05
-
-
Save Oxicode/0141d68c066c5ebacd71 to your computer and use it in GitHub Desktop.
This file contains 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 characters
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; | |
} |
This file contains 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 characters
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