Issues (24)

src/Manager/HasDrivers.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Nip\Logger\Manager;
4
5
use Nip\Logger\Logger;
6
use Throwable;
7
8
/**
9
 * Trait HasDrivers
10
 * @package Nip\Logger\Traits
11
 */
12
trait HasDrivers
13
{
14
15
    /**
16
     * Get a log driver instance.
17
     *
18
     * @param string|null $driver
19
     * @return Logger|\Psr\Log\LoggerInterface
20
     */
21 4
    public function driver($driver = null)
22
    {
23 4
        return $this->get($driver ?? $this->getDefaultDriver());
24
    }
25
26
    /**
27
     * Get the default log driver name.
28
     *
29
     * @return string
30
     */
31 1
    public function getDefaultDriver()
32
    {
33 1
        return static::getPackageConfig("default", 'single');
34
    }
35
36
    /**
37
     * Attempt to get the log from the local cache.
38
     *
39
     * @param string $name
40
     * @return \Psr\Log\LoggerInterface
41
     */
42 4
    protected function get($name)
43
    {
44
        try {
45 4
            return $this->channels[$name] ?? $this->initDriver($name);
46
        } catch (Throwable $exception) {
47
            return $this->createEmergencyLogger();
0 ignored issues
show
It seems like createEmergencyLogger() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
            return $this->/** @scrutinizer ignore-call */ createEmergencyLogger();
Loading history...
48
        }
49
    }
50
51
    /**
52
     * @param string $name
53
     * @return mixed
54
     */
55
    abstract protected function initDriver($name);
56
}
57