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
49
50
|
<?php
declare(strict_types=1);
namespace OpenTelemetry\API\Behavior;
use OpenTelemetry\API\Behavior\Internal\Logging;
use Psr\Log\LogLevel;
trait LogsMessagesTrait
{
private static function shouldLog(string $level): bool
{
return Logging::level($level) >= Logging::logLevel();
}
private static function doLog(string $level, string $message, array $context): void
{
$writer = Logging::logWriter();
if (self::shouldLog($level)) {
$context['source'] = get_called_class();
$writer->write($level, $message, $context);
}
}
protected static function logDebug(string $message, array $context = []): void
{
self::doLog(LogLevel::DEBUG, $message, $context);
}
protected static function logInfo(string $message, array $context = []): void
{
self::doLog(LogLevel::INFO, $message, $context);
}
protected static function logNotice(string $message, array $context = []): void
{
self::doLog(LogLevel::NOTICE, $message, $context);
}
protected static function logWarning(string $message, array $context = []): void
{
self::doLog(LogLevel::WARNING, $message, $context);
}
protected static function logError(string $message, array $context = []): void
{
self::doLog(LogLevel::ERROR, $message, $context);
}
}
|