Log   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 35
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setLogger() 0 4 1
A getLogger() 0 4 2
A __callStatic() 0 4 1
A __call() 0 4 1
A createDefaultLogger() 0 7 1
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