1<?php
2/**
3 * Copyright © 2019-2026 Rhubarb Tech Inc. All Rights Reserved.
4 *
5 * The Object Cache Pro Software and its related materials are property and confidential
6 * information of Rhubarb Tech Inc. Any reproduction, use, distribution, or exploitation
7 * of the Object Cache Pro Software and its related materials, in whole or in part,
8 * is strictly forbidden unless prior permission is obtained from Rhubarb Tech Inc.
9 *
10 * In addition, any reproduction, use, distribution, or exploitation of the Object Cache Pro
11 * Software and its related materials, in whole or in part, is subject to the End-User License
12 * Agreement accessible in the included `LICENSE` file, or at: https://objectcache.pro/eula
13 */
14
15declare(strict_types=1);
16
17namespace RedisCachePro\Loggers;
18
19abstract class Logger implements LoggerInterface
20{
21 /**
22 * System is unusable.
23 *
24 * @var string
25 */
26 const EMERGENCY = 'emergency';
27
28 /**
29 * Action must be taken immediately.
30 *
31 * @var string
32 */
33 const ALERT = 'alert';
34
35 /**
36 * Critical conditions.
37 *
38 * @var string
39 */
40 const CRITICAL = 'critical';
41
42 /**
43 * Runtime errors that do not require immediate action but should typically
44 * be logged and monitored.
45 *
46 * @var string
47 */
48 const ERROR = 'error';
49
50 /**
51 * Exceptional occurrences that are not errors.
52 *
53 * @var string
54 */
55 const WARNING = 'warning';
56
57 /**
58 * Normal but significant events.
59 *
60 * @var string
61 */
62 const NOTICE = 'notice';
63
64 /**
65 * Interesting events.
66 *
67 * @var string
68 */
69 const INFO = 'info';
70
71 /**
72 * Detailed debug information.
73 *
74 * @var string
75 */
76 const DEBUG = 'debug';
77
78 /**
79 * Logged levels.
80 *
81 * @var string[]|null
82 */
83 protected $levels;
84
85 /**
86 * System is unusable.
87 *
88 * @param string $message
89 * @param array<mixed> $context
90 * @return void
91 */
92 public function emergency($message, array $context = [])
93 {
94 $this->log(self::EMERGENCY, $message, $context);
95 }
96
97 /**
98 * Action must be taken immediately.
99 *
100 * Example: Entire website down, database unavailable, etc. This should
101 * trigger the SMS alerts and wake you up.
102 *
103 * @param string $message
104 * @param array<mixed> $context
105 * @return void
106 */
107 public function alert($message, array $context = [])
108 {
109 $this->log(self::ALERT, $message, $context);
110 }
111
112 /**
113 * Critical conditions.
114 *
115 * Example: Application component unavailable, unexpected exception.
116 *
117 * @param string $message
118 * @param array<mixed> $context
119 * @return void
120 */
121 public function critical($message, array $context = [])
122 {
123 $this->log(self::CRITICAL, $message, $context);
124 }
125
126 /**
127 * Runtime errors that do not require immediate action but should typically
128 * be logged and monitored.
129 *
130 * @param string $message
131 * @param array<mixed> $context
132 * @return void
133 */
134 public function error($message, array $context = [])
135 {
136 $this->log(self::ERROR, $message, $context);
137 }
138
139 /**
140 * Exceptional occurrences that are not errors.
141 *
142 * Example: Use of deprecated APIs, poor use of an API, undesirable things
143 * that are not necessarily wrong.
144 *
145 * @param string $message
146 * @param array<mixed> $context
147 * @return void
148 */
149 public function warning($message, array $context = [])
150 {
151 $this->log(self::WARNING, $message, $context);
152 }
153
154 /**
155 * Normal but significant events.
156 *
157 * @param string $message
158 * @param array<mixed> $context
159 * @return void
160 */
161 public function notice($message, array $context = [])
162 {
163 $this->log(self::NOTICE, $message, $context);
164 }
165
166 /**
167 * Interesting events.
168 *
169 * Example: User logs in, SQL logs.
170 *
171 * @param string $message
172 * @param array<mixed> $context
173 * @return void
174 */
175 public function info($message, array $context = [])
176 {
177 $this->log(self::INFO, $message, $context);
178 }
179
180 /**
181 * Detailed debug information.
182 *
183 * @param string $message
184 * @param array<mixed> $context
185 * @return void
186 */
187 public function debug($message, array $context = [])
188 {
189 $this->log(self::DEBUG, $message, $context);
190 }
191
192 /**
193 * Logs with an arbitrary level.
194 *
195 * @param mixed $level
196 * @param string $message
197 * @param array<mixed> $context
198 * @return void
199 */
200 abstract public function log($level, $message, array $context = []);
201
202 /**
203 * Set the logged levels.
204 *
205 * @param string[] $levels
206 * @return void
207 */
208 public function setLevels(array $levels)
209 {
210 $this->levels = $levels;
211 }
212}
213