Failed Conditions
Pull Request — master (#1861)
by k-yamamura
501:04 queued 494:33
created

EccubeLogger   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 50
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 8 2
A log() 0 21 4
1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
namespace Eccube\Monolog;
25
26
use Eccube\Application;
27
use Psr\Log\AbstractLogger;
28
29
class EccubeLogger extends AbstractLogger
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
30
{
31
32
    protected static $instance;
33
34
    /**
35
     *
36
     * Returns a singleton of the EccubeLogger
37
     *
38
     * @return EccubeLogger
39
     */
40 463
    public static function getInstance()
41
    {
42 463
        if (!is_object(self::$instance)) {
43 1
            self::$instance = new EccubeLogger();
44 1
        }
45
46 463
        return self::$instance;
47
    }
48
49
    /**
50
     * ログ出力を行う。アクセスされている画面によりログ出力先を分けている。
51
     *
52
     * @param mixed $level
0 ignored issues
show
introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
53
     * @param string $message
54
     * @param array $context
0 ignored issues
show
introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
55
     */
56 463
    public function log($level, $message, array $context = array())
57
    {
58 463
        $app = Application::getInstance();
59
60 463
        if ($app->isFrontRequest()) {
61
            // フロント画面用のログ出力
62 171
            $app['monolog.logger.front']->log($level, $message, $context);
63 463
        } elseif ($app->isAdminRequest()) {
64
            // 管理画面用のログ出力
65 291
            $app['monolog.logger.admin']->log($level, $message, $context);
66 291
        } else {
67
            // 両方に当てはまらない場合、monolog用へログ出力
68 3
            $app['monolog']->log($level, $message, $context);
69
        }
70
71 463
        if ($app['debug']) {
72
            // debugが有効時はフロント、管理両方のログをmonologにも出力
73 463
            $app['monolog']->log($level, $message, $context);
74 460
        }
75
76 463
    }
77
78
}
79