Log4PhpToPsrLoggerAdapter   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 3
dl 0
loc 118
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A injectPsrLogger() 0 4 1
A trace() 0 4 1
A debug() 0 4 1
A info() 0 4 1
A warn() 0 4 1
A error() 0 4 1
A fatal() 0 4 1
B log() 0 21 7
1
<?php
2
/**
3
 * @author stev leibelt <[email protected]>
4
 * @since 2013-09-13 
5
 */
6
7
namespace Net\Bazzline\Component\PsrAndLog4PhpAdapter;
8
9
use Exception;
10
use Logger;
11
use LoggerLevel;
12
use Psr\Log\LoggerInterface;
13
14
/**
15
 * Class Log4PhpToPsrLoggerAdapter
16
 *
17
 * @package Net\Bazzline\Component\PsrAndLog4PhpAdapter
18
 */
19
class Log4PhpToPsrLoggerAdapter extends Logger
20
{
21
    /** @var LoggerInterface */
22
    private $psrLogger;
23
24
    /**
25
     * Log4PhpToPsrLoggerAdapter constructor.
26
     *
27
     * @param LoggerInterface $psrLogger
28
     */
29
    public function injectPsrLogger(LoggerInterface $psrLogger)
30
    {
31
        $this->psrLogger    = $psrLogger;
32
    }
33
34
35
    /**
36
     * Log a message object with the TRACE level.
37
     *
38
     * @param mixed $message message
39
     * @param Exception $throwable Optional throwable information to include
40
     *   in the logging event.
41
     */
42
    public function trace($message, $throwable = null)
43
    {
44
        $this->log(LoggerLevel::getLevelTrace(), $message, $throwable);
45
    }
46
47
    /**
48
     * Log a message object with the DEBUG level.
49
     *
50
     * @param mixed $message message
51
     * @param Exception $throwable Optional throwable information to include
52
     *   in the logging event.
53
     */
54
    public function debug($message, $throwable = null)
55
    {
56
        $this->log(LoggerLevel::getLevelDebug(), $message, $throwable);
57
    }
58
59
    /**
60
     * Log a message object with the INFO Level.
61
     *
62
     * @param mixed $message message
63
     * @param Exception $throwable Optional throwable information to include
64
     *   in the logging event.
65
     */
66
    public function info($message, $throwable = null)
67
    {
68
        $this->log(LoggerLevel::getLevelInfo(), $message, $throwable);
69
    }
70
71
    /**
72
     * Log a message with the WARN level.
73
     *
74
     * @param mixed $message message
75
     * @param Exception $throwable Optional throwable information to include
76
     *   in the logging event.
77
     */
78
    public function warn($message, $throwable = null)
79
    {
80
        $this->log(LoggerLevel::getLevelWarn(), $message, $throwable);
81
    }
82
83
    /**
84
     * Log a message object with the ERROR level.
85
     *
86
     * @param mixed $message message
87
     * @param Exception $throwable Optional throwable information to include
88
     *   in the logging event.
89
     */
90
    public function error($message, $throwable = null)
91
    {
92
        $this->log(LoggerLevel::getLevelError(), $message, $throwable);
93
    }
94
95
    /**
96
     * Log a message object with the FATAL level.
97
     *
98
     * @param mixed $message message
99
     * @param Exception $throwable Optional throwable information to include
100
     *   in the logging event.
101
     */
102
    public function fatal($message, $throwable = null)
103
    {
104
        $this->log(LoggerLevel::getLevelFatal(), $message, $throwable);
105
    }
106
107
    /**
108
     * Log a message using the provided logging level.
109
     *
110
     * @param LoggerLevel $level The logging level.
111
     * @param mixed $message Message to log.
112
     * @param Exception $throwable Optional throwable information to include
113
     *   in the logging event.
114
     */
115
    public function log(LoggerLevel $level, $message, $throwable = null)
116
    {
117
        switch ($level->toInt()) {
118
            case LoggerLevel::TRACE:
119
            case LoggerLevel::DEBUG:
120
                $this->psrLogger->debug($message);
121
                break;
122
            case LoggerLevel::INFO:
123
                $this->psrLogger->info($message);
124
                break;
125
            case LoggerLevel::WARN:
126
                $this->psrLogger->warning($message);
127
                break;
128
            case LoggerLevel::ERROR:
129
                $this->psrLogger->error($message);
130
                break;
131
            case LoggerLevel::FATAL:
132
                $this->psrLogger->emergency($message);
133
                break;
134
        }
135
    }
136
}
137