mirror of
https://github.com/zhamao-robot/zhamao-logger.git
synced 2026-03-17 20:44:52 +08:00
add static context support
This commit is contained in:
parent
bfa816f734
commit
5423de6df5
@ -65,6 +65,13 @@ class ConsoleLogger extends AbstractLogger
|
||||
*/
|
||||
protected static $log_level;
|
||||
|
||||
/**
|
||||
* 静态上下文
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $static_context = [];
|
||||
|
||||
/**
|
||||
* 创建一个 ConsoleLogger 实例
|
||||
*
|
||||
@ -147,10 +154,18 @@ class ConsoleLogger extends AbstractLogger
|
||||
[date(self::$date_format), strtoupper(substr(self::$levels[$level], 0, 4)), $message],
|
||||
self::$format
|
||||
);
|
||||
$output = $this->interpolate($output, $context);
|
||||
$output = $this->interpolate($output, array_merge($this->static_context, $context));
|
||||
echo $this->colorize($output, $level) . "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加静态上下文
|
||||
*/
|
||||
public function addStaticContext(array $context): void
|
||||
{
|
||||
$this->static_context = array_merge($this->static_context, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换日志等级
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user