diff --git a/Base/Model.php b/Base/Model.php index e0c7630..e98fe65 100644 --- a/Base/Model.php +++ b/Base/Model.php @@ -575,7 +575,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \ } $validate = $this->resolve($rule); if (!$validate->validation($params)) { - return \Kiri::getLogger()->failure($validate->getError() . PHP_EOL, 'mysql'); + return \Kiri::getLogger()->logCategory($validate->getError() . PHP_EOL, 'mysql'); } else { return TRUE; } diff --git a/Collection.php b/Collection.php index ab2c8da..ce4c495 100644 --- a/Collection.php +++ b/Collection.php @@ -41,7 +41,7 @@ class Collection extends AbstractCollection public function update(array $attributes): bool { if ($this->isEmpty()) { - return $this->getLogger()->failure('No data by update', 'mysql'); + return $this->getLogger()->logCategory('No data by update', 'mysql'); } return $this->batch()->update($attributes); } @@ -150,7 +150,7 @@ class Collection extends AbstractCollection { $model = $this->getModel(); if ($this->isEmpty()) { - return $this->getLogger()->failure('No data by delete', 'mysql'); + return $this->getLogger()->logCategory('No data by delete', 'mysql'); } if (!$model->hasPrimary()) { throw new Exception('Must set primary key. if you want to delete data'); diff --git a/Command.php b/Command.php index b7101fd..8ef57a6 100644 --- a/Command.php +++ b/Command.php @@ -123,13 +123,15 @@ class Command extends Component return $result; } catch (Throwable $throwable) { - $this->getLogger()->failure(throwable($throwable), 'mysql'); + $this->getLogger()->json_log($throwable); - if ($this->isRefresh($throwable)) return $this->search($method); + if ($this->isRefresh($throwable)) { + return $this->search($method); + } $errorMsg = $throwable->getMessage() . PHP_EOL . ' Sql: ' . $this->sql . '.' . json_encode($this->params); - return $this->getLogger()->failure($errorMsg . PHP_EOL, 'mysql'); + return $this->getLogger()->logCategory($errorMsg . PHP_EOL, 'mysql'); } finally { $this->connection->release($client); } @@ -169,13 +171,15 @@ class Command extends Component return $result == 0 ? $prepare->rowCount() : (int)$result; } catch (Throwable $throwable) { - $this->getLogger()->failure(throwable($throwable), 'mysql'); + $this->getLogger()->json_log($throwable); - if ($this->isRefresh($throwable)) return $this->_prepare(); + if ($this->isRefresh($throwable)) { + return $this->_prepare(); + } $errorMsg = $throwable->getMessage() . PHP_EOL . ' Sql: ' . $this->sql . '.' . json_encode($this->params); - return $this->getLogger()->failure($errorMsg . PHP_EOL, 'mysql'); + return $this->getLogger()->logCategory($errorMsg . PHP_EOL, 'mysql'); } finally { $this->connection->release($client); } diff --git a/Model.php b/Model.php index 508b09a..107140f 100644 --- a/Model.php +++ b/Model.php @@ -116,8 +116,9 @@ class Model extends Base\Model $connection->commit(); return $select; } catch (\Throwable $throwable) { - $connection->rollback(); - return \Kiri::getLogger()->failure($throwable); + $model->getLogger()->json_log($throwable); + $connection->rollback(); + return false; } } @@ -145,8 +146,9 @@ class Model extends Base\Model $connection->commit(); return $select; } catch (\Throwable $throwable) { - $connection->rollback(); - return \Kiri::getLogger()->failure($throwable); + $model->getLogger()->json_log($throwable); + $connection->rollback(); + return false; } } @@ -206,9 +208,10 @@ class Model extends Base\Model public static function inserts(array $data): bool { if (empty($data)) { - return trigger_print_error('Insert data empty.', 'mysql'); - } - return static::query()->insert($data); + return \Kiri::getLogger()->logCategory('Insert data empty.', 'mysql'); + } else { + return static::query()->insert($data); + } } /** diff --git a/SqlBuilder.php b/SqlBuilder.php index a3067de..a734a8a 100644 --- a/SqlBuilder.php +++ b/SqlBuilder.php @@ -108,7 +108,7 @@ class SqlBuilder extends Component private function __updateBuilder(array $string): string|bool { if (empty($string)) { - return Kiri::getLogger()->failure('None data update.'); + return Kiri::getLogger()->logCategory('None data update.'); } return 'UPDATE ' . $this->query->getFrom() . ' SET ' . implode(',', $string) . $this->make(); } @@ -452,7 +452,8 @@ class SqlBuilder extends Component } } catch (\Throwable $e) { // 忽略错误,返回默认值 - } + $this->getLogger()->json_log($e); + } // 默认返回 mysql return 'mysql'; }