Skip to content

Commit

Permalink
Merge pull request #466 from gaobinzhan/3.x
Browse files Browse the repository at this point in the history
add: log ingore category
  • Loading branch information
kiss291323003 authored Mar 7, 2021
2 parents b0ece32 + 323791c commit 9fa0410
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 29 deletions.
64 changes: 37 additions & 27 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function __construct(LoggerInterface $logger)

public function logLevel(?int $level = null)
{
if($level !== null){
if ($level !== null) {
$this->logLevel = $level;
return $this;
}
Expand All @@ -44,74 +44,84 @@ public function logLevel(?int $level = null)

public function logConsole(?bool $is = null)
{
if($is === null){
if ($is === null) {
return $this->logConsole;
}else{
} else {
$this->logConsole = $is;
return $this;
}
}

public function ignoreCategory(?array $arr = null)
{
if($arr === null){
if ($arr === null) {
return $this->ignoreCategory;
}else{
} else {
$this->ignoreCategory = $arr;
return $this;
}
}

public function log(?string $msg,int $logLevel = LoggerInterface::LOG_LEVEL_DEBUG,string $category = 'debug')
public function log(?string $msg, int $logLevel = LoggerInterface::LOG_LEVEL_DEBUG, string $category = 'debug')
{
if($logLevel < $this->logLevel){
if ($logLevel < $this->logLevel) {
return;
}
$this->logger->log($msg,$logLevel,$category);

if (in_array($category, $this->ignoreCategory)) {
return;
}

$this->logger->log($msg, $logLevel, $category);
$calls = $this->callback->all();
foreach ($calls as $call){
call_user_func($call,$msg,$logLevel,$category);
foreach ($calls as $call) {
call_user_func($call, $msg, $logLevel, $category);
}
}

public function console(?string $msg,int $logLevel = LoggerInterface::LOG_LEVEL_DEBUG,string $category = 'debug')
public function console(?string $msg, int $logLevel = LoggerInterface::LOG_LEVEL_DEBUG, string $category = 'debug')
{
if($logLevel < $this->logLevel){
if ($logLevel < $this->logLevel) {
return;
}
$this->logger->console($msg,$logLevel,$category);
if($this->logConsole){
$this->log($msg,$logLevel,$category);

if (in_array($category, $this->ignoreCategory)) {
return;
}

$this->logger->console($msg, $logLevel, $category);
if ($this->logConsole) {
$this->log($msg, $logLevel, $category);
}
}

public function debug(?string $msg,string $category = 'debug')
public function debug(?string $msg, string $category = 'debug')
{
$this->console($msg,LoggerInterface::LOG_LEVEL_DEBUG,$category);
$this->console($msg, LoggerInterface::LOG_LEVEL_DEBUG, $category);
}

public function info(?string $msg,string $category = 'info')
public function info(?string $msg, string $category = 'info')
{
$this->console($msg,LoggerInterface::LOG_LEVEL_INFO,$category);
$this->console($msg, LoggerInterface::LOG_LEVEL_INFO, $category);
}

public function notice(?string $msg,string $category = 'notice')
public function notice(?string $msg, string $category = 'notice')
{
$this->console($msg,LoggerInterface::LOG_LEVEL_NOTICE,$category);
$this->console($msg, LoggerInterface::LOG_LEVEL_NOTICE, $category);
}

public function waring(?string $msg,string $category = 'waring')
public function waring(?string $msg, string $category = 'waring')
{
$this->console($msg,LoggerInterface::LOG_LEVEL_WARNING,$category);
$this->console($msg, LoggerInterface::LOG_LEVEL_WARNING, $category);
}

public function error(?string $msg,string $category = 'error')
public function error(?string $msg, string $category = 'error')
{
$this->console($msg,LoggerInterface::LOG_LEVEL_ERROR,$category);
$this->console($msg, LoggerInterface::LOG_LEVEL_ERROR, $category);
}

public function onLog():Event
public function onLog(): Event
{
return $this->callback;
}
}
}
4 changes: 2 additions & 2 deletions src/Resource/Config._php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ return [
'dir' => null,
'level' => LoggerInterface::LOG_LEVEL_DEBUG,
'handler' => null,
'logConsole'=>true,
'ignoreCategory'=>[]
'logConsole' => true,
'ignoreCategory' => []
],
'TEMP_DIR' => null
];

0 comments on commit 9fa0410

Please sign in to comment.