diff --git a/src/ZM/Logger/ConsoleLogger.php b/src/ZM/Logger/ConsoleLogger.php index ae2eb7b..69732c5 100644 --- a/src/ZM/Logger/ConsoleLogger.php +++ b/src/ZM/Logger/ConsoleLogger.php @@ -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); + } + /** * 转换日志等级 */