summaryrefslogtreecommitdiff
path: root/vendor/open-telemetry/api/LoggerHolder.php
blob: 99f916a23d9516731910bba0815d368ad61061fe (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
49
50
51
52
53
<?php

declare(strict_types=1);

namespace OpenTelemetry\API;

use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

final class LoggerHolder
{
    private static ?LoggerInterface $logger = null;

    /**
     * This constructor is a temporary solution to ease the setup of the logger with DI libraries
     */
    public function __construct(?LoggerInterface $logger = null)
    {
        self::$logger = $logger;
    }

    /**
     * @suppress PhanTypeMismatchReturnNullable
     * @internal
     */
    public static function get(): ?LoggerInterface
    {
        return self::$logger;
    }

    public static function set(?LoggerInterface $logger): void
    {
        self::$logger = $logger;
    }

    public static function isSet(): bool
    {
        return null !== self::$logger;
    }

    public static function unset(): void
    {
        self::$logger = null;
    }

    /**
     * Disable psr-3 logging
     */
    public static function disable(): void
    {
        self::$logger = new NullLogger();
    }
}