-
Notifications
You must be signed in to change notification settings - Fork 192
/
Copy pathLoggerProvider.php
56 lines (46 loc) · 2.01 KB
/
LoggerProvider.php
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
51
52
53
54
55
56
<?php
declare(strict_types=1);
namespace OpenTelemetry\SDK\Logs;
use OpenTelemetry\API\Logs\LoggerInterface;
use OpenTelemetry\API\Logs\NoopLogger;
use OpenTelemetry\SDK\Common\Future\CancellationInterface;
use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeFactoryInterface;
use OpenTelemetry\SDK\Resource\ResourceInfo;
use OpenTelemetry\SDK\Resource\ResourceInfoFactory;
class LoggerProvider implements LoggerProviderInterface
{
private LoggerSharedState $loggerSharedState;
private InstrumentationScopeFactoryInterface $instrumentationScopeFactory;
public function __construct(LogRecordProcessorInterface $processor, InstrumentationScopeFactoryInterface $instrumentationScopeFactory, ?ResourceInfo $resource = null)
{
$this->loggerSharedState = new LoggerSharedState(
$resource ?? ResourceInfoFactory::defaultResource(),
(new LogRecordLimitsBuilder())->build(),
$processor
);
$this->instrumentationScopeFactory = $instrumentationScopeFactory;
}
/**
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/sdk.md#logger-creation
*/
public function getLogger(string $name, ?string $version = null, ?string $schemaUrl = null, iterable $attributes = []): LoggerInterface
{
if ($this->loggerSharedState->hasShutdown()) {
return NoopLogger::getInstance();
}
$scope = $this->instrumentationScopeFactory->create($name, $version, $schemaUrl, $attributes);
return new Logger($this->loggerSharedState, $scope);
}
public function shutdown(CancellationInterface $cancellation = null): bool
{
return $this->loggerSharedState->shutdown($cancellation);
}
public function forceFlush(CancellationInterface $cancellation = null): bool
{
return $this->loggerSharedState->forceFlush($cancellation);
}
public static function builder(): LoggerProviderBuilder
{
return new LoggerProviderBuilder();
}
}