This commit is contained in:
2021-03-05 15:04:35 +08:00
parent cc88c8ca79
commit dde258d611
+18 -6
View File
@@ -16,6 +16,7 @@ use Exception;
use PDO; use PDO;
use PDOStatement; use PDOStatement;
use Snowflake\Abstracts\Config; use Snowflake\Abstracts\Config;
use Snowflake\Exception\ComponentException;
use Snowflake\Exception\NotFindClassException; use Snowflake\Exception\NotFindClassException;
/** /**
@@ -127,15 +128,10 @@ class Command extends Component
} else { } else {
$result = $this->search($type); $result = $this->search($type);
} }
$this->setExecuteLog($time);
if ($this->prepare) { if ($this->prepare) {
$this->prepare->closeCursor(); $this->prepare->closeCursor();
} }
logger()->debug($this->sql . var_export($this->params, true), 'mysql');
if (Config::get('debug.enable', false, false)) {
$this->debug($this->sql . '。 Run-time: ' . (microtime(true) - $time));
}
} catch (\Throwable $exception) { } catch (\Throwable $exception) {
$result = $this->addError($this->sql . '. error: ' . $exception->getMessage(), 'mysql'); $result = $this->addError($this->sql . '. error: ' . $exception->getMessage(), 'mysql');
} finally { } finally {
@@ -143,6 +139,22 @@ class Command extends Component
} }
} }
/**
* @param $time
* @throws ComponentException
* @throws Exception
*/
private function setExecuteLog($time)
{
$export['sql'] = $this->sql;
$export['param'] = $this->params;
$export['time'] = microtime(true) - $time;
logger()->debug(var_export($export, true), 'mysql');
}
/** /**
* @param $type * @param $type
* @return mixed * @return mixed