mirror of
https://github.com/zhamao-robot/zhamao-logger.git
synced 2026-07-02 14:25:40 +08:00
add static context support
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换日志等级
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user