forked from thecodingmachine/graphqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionLogger.php
More file actions
31 lines (26 loc) · 851 Bytes
/
ExceptionLogger.php
File metadata and controls
31 lines (26 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
declare(strict_types=1);
namespace TheCodingMachine\GraphQLite\Loggers;
use Exception;
use Psr\Log\AbstractLogger;
use Psr\Log\LogLevel;
use Stringable;
use Throwable;
use function in_array;
/**
* A logger that throws an exception on WARN, ERROR, FATAL.
* Useful to detect errors in PSR-16 caches (that never throw exceptions but that log things)
*/
class ExceptionLogger extends AbstractLogger
{
/** @inheritDoc */
public function log($level, $message, array $context = []): void
{
if (in_array($level, [LogLevel::EMERGENCY, LogLevel::ALERT, LogLevel::CRITICAL, LogLevel::ERROR, LogLevel::WARNING])) {
if (isset($context['exception']) && $context['exception'] instanceof Throwable) {
throw $context['exception'];
}
throw new Exception($message);
}
}
}