Skip to content

Commit 6d01946

Browse files
rmachado-studocutimacdonald
authored andcommitted
feat: Adds shareContext to LogFake
1 parent 600bf55 commit 6d01946

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/LogFake.php

+18
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ class LogFake implements LoggerInterface
3030
*/
3131
private array $stacks = [];
3232

33+
/**
34+
* The context shared across channels and stacks.
35+
*
36+
* @var array
37+
*/
38+
protected $sharedContext = [];
39+
3340
/**
3441
* @link https://github.com/timacdonald/log-fake#basic-usage Documentation
3542
*/
@@ -225,4 +232,15 @@ private static function parseStackDriver(array $channels, ?string $channel): str
225232
{
226233
return 'stack::'.($channel ?? 'unnamed').':'.Collection::make($channels)->sort()->implode(',');
227234
}
235+
236+
public function shareContext(array $context): LogFake
237+
{
238+
foreach ($this->channels as $channel) {
239+
$channel->withContext($context);
240+
}
241+
242+
$this->sharedContext = array_merge($this->sharedContext, $context);
243+
244+
return $this;
245+
}
228246
}

0 commit comments

Comments
 (0)