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