Passed
Push — master ( 535bd5...f77f61 )
by wannanbigpig
03:11
created

LogServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 36
ccs 10
cts 11
cp 0.9091
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A logConfig() 0 13 2
A register() 0 6 1
1
<?php
2
/*
3
 * This file is part of the wannanbigpig/alipay-sdk-php.
4
 *
5
 * (c) wannanbigpig <[email protected]>
6
 *
7
 * This source file is subject to the MIT license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace EasyAlipay\Kernel\Providers;
12
13
use Pimple\Container;
14
use Pimple\ServiceProviderInterface;
15
use WannanBigPig\Supports\Logs\Log;
16
17
/**
18
 * Class LogServiceProvider
19
 *
20
 * @author   liuml  <[email protected]>
21
 * @DateTime 2019-07-18  17:00
22
 */
23
class LogServiceProvider implements ServiceProviderInterface
24
{
25
    /**
26
     * Registers services on the given container.
27
     *
28
     * @param Container $pimple A container instance
29
     */
30
    public function register(Container $pimple)
31
    {
32 14
        $pimple['logger'] = function ($app) {
33 14
            $config = $this->logConfig($app);
34
35 14
            return new Log($config);
36
        };
37 62
    }
38
39
    /**
40
     * Get the log configuration.
41
     *
42
     * @param $app
43
     *
44
     * @return array
45
     */
46 14
    public function logConfig($app)
47
    {
48 14
        $logConfig = [];
49 14
        if (!empty($app['config']->get('log'))) {
50
            $logConfig = $app['config']->get('log');
51
        }
52
53 14
        return array_merge([
54 14
            'driver' => 'single',
55
            'level' => 'notice',
56
            'format' => "%datetime% > %channel% [ %level_name% ] > %message% %context% %extra%\n",
57
            'path' => '/tmp/wannanbigpig.alipay.log',
58 14
        ], $logConfig);
59
    }
60
}
61