xref: /plugin/smtp/classes/Logger.php (revision ee5c02056e482f4a07fb4b075ec45c4dfd3de0e8)
1<?php
2
3namespace splitbrain\dokuwiki\plugin\smtp;
4
5use Psr\Log\LoggerInterface;
6
7/**
8 * Simple PSR-3 logger
9 *
10 * Simply logs to an internal variable
11 *
12 * @package splitbrain\dokuwiki\plugin\smtp
13 */
14class Logger implements LoggerInterface
15{
16    protected $log = [];
17
18    /**
19     * Get all log messages
20     *
21     * @return array
22     */
23    public function getLog()
24    {
25        return $this->log;
26    }
27
28    /**
29     * System is unusable.
30     *
31     * @param string $message
32     * @param array $context
33     */
34    public function emergency($message, array $context = [])
35    {
36        $this->log('emergency', $message, $context);
37    }
38
39    /**
40     * Action must be taken immediately.
41     *
42     * Example: Entire website down, database unavailable, etc. This should
43     * trigger the SMS alerts and wake you up.
44     *
45     * @param string $message
46     * @param array $context
47     */
48    public function alert($message, array $context = [])
49    {
50        $this->log('alert', $message, $context);
51    }
52
53    /**
54     * Critical conditions.
55     *
56     * Example: Application component unavailable, unexpected exception.
57     *
58     * @param string $message
59     * @param array $context
60     */
61    public function critical($message, array $context = [])
62    {
63        $this->log('critical', $message, $context);
64    }
65
66    /**
67     * Runtime errors that do not require immediate action but should typically
68     * be logged and monitored.
69     *
70     * @param string $message
71     * @param array $context
72     */
73    public function error($message, array $context = [])
74    {
75        $this->log('error', $message, $context);
76    }
77
78    /**
79     * Exceptional occurrences that are not errors.
80     *
81     * Example: Use of deprecated APIs, poor use of an API, undesirable things
82     * that are not necessarily wrong.
83     *
84     * @param string $message
85     * @param array $context
86     */
87    public function warning($message, array $context = [])
88    {
89        $this->log('warning', $message, $context);
90    }
91
92    /**
93     * Normal but significant events.
94     *
95     * @param string $message
96     * @param array $context
97     */
98    public function notice($message, array $context = [])
99    {
100        $this->log('notice', $message, $context);
101    }
102
103    /**
104     * Interesting events.
105     *
106     * Example: User logs in, SQL logs.
107     *
108     * @param string $message
109     * @param array $context
110     */
111    public function info($message, array $context = [])
112    {
113        $this->log('info', $message, $context);
114    }
115
116    /**
117     * Detailed debug information.
118     *
119     * @param string $message
120     * @param array $context
121     */
122    public function debug($message, array $context = [])
123    {
124        $this->log('debug', $message, $context);
125    }
126
127    /**
128     * Logs with an arbitrary level.
129     *
130     * @param mixed $level
131     * @param string $message
132     * @param array $context
133     */
134    public function log($level, $message, array $context = [])
135    {
136        $this->log[] = [$level, $message, $context];
137    }
138}
139