Skip to content

Commit

Permalink
feat: Adds shareContext to LogFake
Browse files Browse the repository at this point in the history
  • Loading branch information
rmachado-studocu committed Jun 7, 2023
1 parent 0d32515 commit 7b634bb
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/LogFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class LogFake implements LoggerInterface
*/
private array $stacks = [];

/**
* The context shared across channels and stacks.
*
* @var array
*/
protected $sharedContext = [];

/**
* @link https://github.com/timacdonald/log-fake#basic-usage Documentation
*/
Expand Down Expand Up @@ -220,4 +227,15 @@ private static function parseStackDriver(array $channels, ?string $channel): str
{
return 'stack::' . ($channel ?? 'unnamed') . ':' . Collection::make($channels)->sort()->implode(',');
}

public function shareContext(array $context): LogFake
{
foreach ($this->channels as $channel) {
$channel->withContext($context);
}

$this->sharedContext = array_merge($this->sharedContext, $context);

return $this;
}
}

0 comments on commit 7b634bb

Please sign in to comment.