Test Failed
Push — master ( a29797...6ce97f )
by huang
06:37
created

LoggerServiceProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 88.24%

Importance

Changes 3
Bugs 2 Features 0
Metric Value
dl 0
loc 25
rs 10
c 3
b 2
f 0
ccs 15
cts 17
cp 0.8824
wmc 6
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B register() 0 19 6
1
<?php
2
/**
3
 * @author    jan huang <[email protected]>
4
 * @copyright 2016
5
 *
6
 * @see      https://www.github.com/janhuang
7
 * @see      https://fastdlabs.com
8
 */
9
10
namespace FastD\ServiceProvider;
11
12
use FastD\Container\Container;
13
use FastD\Container\ServiceProviderInterface;
14
use Monolog\Formatter\LineFormatter;
15
use Monolog\Handler\AbstractHandler;
16
17
/**
18
 * Class LoggerServiceProvider.
19
 */
20
class LoggerServiceProvider implements ServiceProviderInterface
21
{
22
    /**
23
     * @param Container $container
24
     */
25 37
    public function register(Container $container)
26
    {
27 37
        $handlers = config()->get('log', []);
28 37
        $path = app()->getPath().'/runtime/logs';
29
30 37
        foreach ($handlers as $handler) {
31 37
            list($handle, $name, $level, $format) = array_pad($handler, 4, null);
32 37
            if (is_string($handle)) {
33 37
                $handle = new $handle($path.'/'.$name, $level);
34 37
            }
35 37
            if ($handle instanceof AbstractHandler) {
36 37
                if (null === $format) {
37
                    $format = new LineFormatter();
38
                }
39 37
                $handle->setFormatter(is_string($format) ? new $format() : $format);
40 37
                Logger()->pushHandler($handle);
41 37
            }
42 37
        }
43 37
    }
44
}
45