-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setLog方法支持传入闭包对日志进行处理 废弃getDbLog、updateQueryTime、clearQueryTime及getQueryTimes方法
- Loading branch information
Showing
2 changed files
with
15 additions
and
25 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,10 +9,11 @@ | |
// +---------------------------------------------------------------------- | ||
// | Author: liu21st <[email protected]> | ||
// +---------------------------------------------------------------------- | ||
declare(strict_types=1); | ||
declare (strict_types = 1); | ||
|
||
namespace think; | ||
|
||
use Closure; | ||
use InvalidArgumentException; | ||
use Psr\Log\LoggerInterface; | ||
use Psr\SimpleCache\CacheInterface; | ||
|
@@ -57,13 +58,6 @@ class DbManager | |
*/ | ||
protected $listen = []; | ||
|
||
/** | ||
* SQL日志. | ||
* | ||
* @var array | ||
*/ | ||
protected $dbLog = []; | ||
|
||
/** | ||
* 查询次数. | ||
* | ||
|
@@ -159,11 +153,11 @@ public function setCache(CacheInterface $cache): void | |
/** | ||
* 设置日志对象 | ||
* | ||
* @param LoggerInterface $log 日志对象 | ||
* @param LoggerInterface|Closure $log 日志对象 | ||
* | ||
* @return void | ||
*/ | ||
public function setLog(LoggerInterface $log): void | ||
public function setLog(LoggerInterface | Closure $log): void | ||
{ | ||
$this->log = $log; | ||
} | ||
|
@@ -179,27 +173,24 @@ public function setLog(LoggerInterface $log): void | |
public function log(string $log, string $type = 'sql') | ||
{ | ||
if ($this->log) { | ||
$this->log->log($type, $log); | ||
} else { | ||
$this->dbLog[$type][] = $log; | ||
if ($this->log instanceof Closure) { | ||
call_user_func_array($this->log, [$type, $log]); | ||
} else { | ||
$this->log->log($type, $log); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* 获得查询日志(没有设置日志对象使用). | ||
* | ||
* @deprecated | ||
* @param bool $clear 是否清空 | ||
* | ||
* @return array | ||
*/ | ||
public function getDbLog(bool $clear = false): array | ||
{ | ||
$logs = $this->dbLog; | ||
if ($clear) { | ||
$this->dbLog = []; | ||
} | ||
|
||
return $logs; | ||
return []; | ||
} | ||
|
||
/** | ||
|
@@ -314,17 +305,16 @@ public function raw(string $value): Raw | |
|
||
/** | ||
* 更新查询次数. | ||
* | ||
* @deprecated | ||
* @return void | ||
*/ | ||
public function updateQueryTimes(): void | ||
{ | ||
$this->queryTimes++; | ||
} | ||
|
||
/** | ||
* 重置查询次数. | ||
* | ||
* @deprecated | ||
* @return void | ||
*/ | ||
public function clearQueryTimes(): void | ||
|
@@ -334,7 +324,7 @@ public function clearQueryTimes(): void | |
|
||
/** | ||
* 获得查询次数. | ||
* | ||
* @deprecated | ||
* @return int | ||
*/ | ||
public function getQueryTimes(): int | ||
|
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