public static function process(Request $request, Response $response) { Lib\Log::debug('Log processing'); Lib\Time::stop('total'); $line = 'REQUEST{% ' . self::requestToString($request) . ' %} RESPONSE{% ' . self::responseToString($response) . ' %} TIME{% ' . Lib\Time::toString() . ' %}'; $status = $response->getStatusCode(); if ($status >= 500) { Lib\Log::error($line); } else { Lib\Log::info($line); } }
private function execute($execType, $statement, $inputParameters = null) { $validExecTypes = [self::EXEC_RETURN_ROW_SET, self::EXEC_RETURN_ROW_COUNT, self::EXEC_RETURN_LAST_INSERTED_ID]; if (!in_array($execType, $validExecTypes)) { throw new \RuntimeException('Model: invalid execute type \'' . $execType . '\''); } $this->reset(); if ($execType == self::EXEC_RETURN_ROW_SET) { $database = $this->database . '::read'; } else { $database = $this->database . '::write'; } $pdo = $this->manager->pdo($database); Log::debug('mysql prepare statement \'' . $statement . '\' with inputParameters: ' . json_encode($inputParameters)); Time::start('mysql'); $PDOStatement = $pdo->prepare($statement); $PDOStatement->execute($inputParameters); Time::stop('mysql'); switch ($execType) { case self::EXEC_RETURN_ROW_SET: $result = $PDOStatement->fetchAll(\PDO::FETCH_ASSOC); break; case self::EXEC_RETURN_ROW_COUNT: $result = $PDOStatement->rowCount(); break; case self::EXEC_RETURN_LAST_INSERTED_ID: $result = $pdo->lastInsertId(); break; } Log::debug('mysql result: ' . json_encode($result)); return $result; }
<?php /** * User: coderd * Date: 2016/1/12 * Time: 11:45 */ use App\Lib\Time; use App\Processor; use App\Config\Env; use App\Config\Res; use App\Lib\Handler\ExceptionHandler; if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR); } define('ROOT_DIR', dirname(dirname(__FILE__))); require __DIR__ . '/../vendor/autoload.php'; Time::start('total'); register_shutdown_function('App\\Lib\\Log::flush'); Env::init(); $app = new Ra\App(Res::$uriPatterns); $app->withExceptionHandler(ExceptionHandler::class . '::process'); $app->matchUriPattern()->call(Processor\Predo::class . '::process')->callResourceAction()->respond()->call(Processor\Log::class . '::process', true);
/** * Dynamically pass methods to the redis * * @param string $method * @param array $parameters * @return mixed */ public function __call($method, $parameters) { Log::debug('redis ' . $method . ' parameters: ' . json_encode($parameters)); $queryType = 'master'; // TODO: determines by operation if (!$this->link($queryType)) { return false; } try { Time::start('redis'); $result = call_user_func_array([$this->link, $method], $parameters); Time::stop('redis'); Log::debug('redis ' . $method . ' result: ' . $result); } catch (\Exception $e) { trigger_error('Errors on operating redis: ' . Str::exceptionToString($e), E_USER_WARNING); return false; } return $result; }