LoggerServiceProvider   A
last analyzed

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 0
Metric Value
dl 0
loc 25
rs 10
c 0
b 0
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 32
    public function register(Container $container)
26
    {
27 32
        $handlers = config()->get('log', []);
28 32
        $path = app()->getPath().'/runtime/logs';
29
30 32
        foreach ($handlers as $handler) {
31 32
            list($handle, $name, $level, $format) = array_pad($handler, 4, null);
32 32
            if (is_string($handle)) {
33 32
                $handle = new $handle($path.'/'.$name, $level);
34 32
            }
35 32
            if ($handle instanceof AbstractHandler) {
36 32
                if (null === $format) {
37
                    $format = new LineFormatter();
38
                }
39 32
                $handle->setFormatter(is_string($format) ? new $format() : $format);
40 32
                Logger()->pushHandler($handle);
41 32
            }
42 32
        }
43 32
    }
44
}
45