Log::__call()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the light/easemob.
5
 *
6
 * (c) lichunqiang <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace light\Easemob\Support;
13
14
use Monolog\Handler\ErrorLogHandler;
15
use Monolog\Logger;
16
use Psr\Log\LoggerInterface;
17
18
/**
19
 * Log.
20
 *
21
 * @method static debug($message, array $context)
22
 * @method static error($message, array $context)
23
 */
24
class Log
25
{
26
    /**
27
     * @var LoggerInterface
28
     */
29
    protected static $_logger;
30
31
    public static function setLogger(LoggerInterface $logger)
32
    {
33
        self::$_logger = $logger;
34
    }
35
36
    public static function getLogger()
37
    {
38
        return self::$_logger ?: self::$_logger = self::createDefaultLogger();
39
    }
40
41
    public static function __callStatic($method, $args)
42
    {
43
        return forward_static_call_array([self::getLogger(), $method], $args);
44
    }
45
46
    public function __call($method, $args)
47
    {
48
        return call_user_func_array([self::getLogger(), $method], $args);
49
    }
50
51
    public static function createDefaultLogger()
52
    {
53
        $logger = new Logger('easemob');
54
        $logger->pushHandler(new ErrorLogHandler());
55
56
        return $logger;
57
    }
58
}
59