blob: 24f5e56a88592248800a1ca9e0729f2b838df6fc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
<?php
declare(strict_types=1);
namespace OpenTelemetry\SDK\Trace\Behavior;
use Psr\Log\LoggerAwareTrait as PsrTrait;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Psr\Log\NullLogger;
trait LoggerAwareTrait
{
use PsrTrait;
private string $defaultLogLevel = LogLevel::INFO;
/**
* @param string $logLevel
*/
public function setDefaultLogLevel(string $logLevel): void
{
$this->defaultLogLevel = $logLevel;
}
/**
* @param string $message
* @param array $context
* @param string|null $level
*/
protected function log(string $message, array $context = [], ?string $level = null): void
{
$this->getLogger()->log(
$level ?? $this->defaultLogLevel,
$message,
$context
);
}
protected function getLogger(): LoggerInterface
{
if ($this->logger !== null) {
return $this->logger;
}
return new NullLogger();
}
}
|