This commit is contained in:
2023-12-13 17:48:07 +08:00
parent 3e73149716
commit 2d1d780618
+16 -8
View File
@@ -13,6 +13,7 @@ namespace Database;
use Exception; use Exception;
use Kiri\Abstracts\Component; use Kiri\Abstracts\Component;
use Kiri\Di\Container; use Kiri\Di\Container;
use Kiri\Error\StdoutLogger;
use PDO; use PDO;
use Throwable; use Throwable;
@@ -130,10 +131,7 @@ class Command extends Component
} catch (Throwable $throwable) { } catch (Throwable $throwable) {
if ($this->isRefresh($throwable)) return $this->search($method); if ($this->isRefresh($throwable)) return $this->search($method);
$logger = $this->getLogger(); return $this->println($throwable)->failure($throwable->getMessage(), 'mysql');
$logger->error($this->sql . '.' . json_encode($this->params) . PHP_EOL . throwable($throwable));
return $logger->failure($throwable->getMessage(), 'mysql');
} finally { } finally {
$this->connection->release($client); $this->connection->release($client);
} }
@@ -172,16 +170,26 @@ class Command extends Component
} catch (Throwable $throwable) { } catch (Throwable $throwable) {
if ($this->isRefresh($throwable)) return $this->_prepare(); if ($this->isRefresh($throwable)) return $this->_prepare();
$logger = $this->getLogger(); return $this->println($throwable)->failure($throwable->getMessage(), 'mysql');
$logger->error($this->sql . '.' . json_encode($this->params) . PHP_EOL . throwable($throwable));
return $logger->failure($throwable->getMessage(), 'mysql');
} finally { } finally {
$this->connection->release($client); $this->connection->release($client);
} }
} }
/**
* @param Throwable $throwable
* @return StdoutLogger
*/
protected function println(Throwable $throwable): StdoutLogger
{
$logger = $this->getLogger();
$error = $this->sql . '.' . json_encode($this->params) . PHP_EOL . throwable($throwable);
file_put_contents('php://output', '[' . date('Y-m-d H:i:s') . '] ' . $error . PHP_EOL, FILE_APPEND);
return $logger;
}
/** /**
* @param Throwable $throwable * @param Throwable $throwable
* @return bool * @return bool