PsrToLog4PhpAdapter::warning()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
/**
3
 * @author stev leibelt <[email protected]>
4
 * @since 2013-09-12
5
 */
6
7
namespace Net\Bazzline\Component\PsrAndLog4PhpAdapter;
8
9
use Logger;
10
use Psr\Log\LoggerInterface;
11
use Psr\Log\LogLevel;
12
13
/**
14
 * Class PsrToLog4PhpAdapter
15
 *
16
 * @package Net\Bazzline\Component\ProxyLogger
17
 */
18
class PsrToLog4PhpAdapter implements LoggerInterface
19
{
20
    /** @var Logger */
21
    private $log4PhpLogger;
22
23
    /**
24
     * PsrToLog4PhpAdapter constructor.
25
     *
26
     * @param Logger $log4PhpLogger
27
     */
28
    public function __construct(Logger $log4PhpLogger)
29
    {
30
        $this->log4PhpLogger    = $log4PhpLogger;
31
    }
32
33
    /**
34
     * System is unusable.
35
     *
36
     * @param string $message
37
     * @param array $context
38
     *
39
     * @return void
40
     */
41
    public function emergency($message, array $context = array())
42
    {
43
        $this->log(LogLevel::EMERGENCY, $message, $context);
44
    }
45
46
    /**
47
     * Action must be taken immediately.
48
     * Example: Entire website down, database unavailable, etc. This should
49
     * trigger the SMS alerts and wake you up.
50
     *
51
     * @param string $message
52
     * @param array $context
53
     *
54
     * @return void
55
     */
56
    public function alert($message, array $context = array())
57
    {
58
        $this->log(LogLevel::ALERT, $message, $context);
59
    }
60
61
    /**
62
     * Critical conditions.
63
     * Example: Application component unavailable, unexpected exception.
64
     *
65
     * @param string $message
66
     * @param array $context
67
     *
68
     * @return void
69
     */
70
    public function critical($message, array $context = array())
71
    {
72
        $this->log(LogLevel::CRITICAL, $message, $context);
73
    }
74
75
    /**
76
     * Runtime errors that do not require immediate action but should typically
77
     * be logged and monitored.
78
     *
79
     * @param string $message
80
     * @param array $context
81
     *
82
     * @return void
83
     */
84
    public function error($message, array $context = array())
85
    {
86
        $this->log(LogLevel::ERROR, $message, $context);
87
    }
88
89
    /**
90
     * Exceptional occurrences that are not errors.
91
     * Example: Use of deprecated APIs, poor use of an API, undesirable things
92
     * that are not necessarily wrong.
93
     *
94
     * @param string $message
95
     * @param array $context
96
     *
97
     * @return void
98
     */
99
    public function warning($message, array $context = array())
100
    {
101
        $this->log(LogLevel::WARNING, $message, $context);
102
    }
103
104
    /**
105
     * Normal but significant events.
106
     *
107
     * @param string $message
108
     * @param array $context
109
     *
110
     * @return void
111
     */
112
    public function notice($message, array $context = array())
113
    {
114
        $this->log(LogLevel::NOTICE, $message, $context);
115
    }
116
117
    /**
118
     * Interesting events.
119
     * Example: User logs in, SQL logs.
120
     *
121
     * @param string $message
122
     * @param array $context
123
     *
124
     * @return void
125
     */
126
    public function info($message, array $context = array())
127
    {
128
        $this->log(LogLevel::INFO, $message, $context);
129
    }
130
131
    /**
132
     * Detailed debug information.
133
     *
134
     * @param string $message
135
     * @param array $context
136
     *
137
     * @return void
138
     */
139
    public function debug($message, array $context = array())
140
    {
141
        $this->log(LogLevel::DEBUG, $message, $context);
142
    }
143
144
    /**
145
     * Logs with an arbitrary level.
146
     *
147
     * @param mixed $level
148
     * @param string $message
149
     * @param array $context
150
     *
151
     * @return void
152
     */
153
    public function log($level, $message, array $context = array())
154
    {
155
        switch ($level) {
156
            case LogLevel::DEBUG:
157
            case LogLevel::NOTICE:
158
                $this->log4PhpLogger->debug($message);
159
                break;
160
            case LogLevel::INFO:
161
                $this->log4PhpLogger->info($message);
162
                break;
163
            case LogLevel::WARNING:
164
                $this->log4PhpLogger->warn($message);
165
                break;
166
            case LogLevel::ERROR:
167
                $this->log4PhpLogger->error($message);
168
                break;
169
            case LogLevel::CRITICAL:
170
            case LogLevel::ALERT:
171
            case LogLevel::EMERGENCY:
172
                $this->log4PhpLogger->fatal($message);
173
                break;
174
        }
175
    }
176
}