Skip to content

Commit ba95cf0

Browse files
committed
Fix monolog compat
1 parent 33568a5 commit ba95cf0

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/Sentry/Laravel/Logs/LogsHandler.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
namespace Sentry\Laravel\Logs;
44

5-
use Illuminate\Support\Arr;
6-
use Monolog\Level;
75
use Sentry\Logs\LogLevel;
86
use Monolog\Formatter\LineFormatter;
97
use Monolog\Formatter\FormatterInterface;
108
use Monolog\Handler\AbstractProcessingHandler;
119
use Sentry\Monolog\CompatibilityProcessingHandlerTrait;
10+
use Sentry\Severity;
1211
use Throwable;
1312

1413
class LogsHandler extends AbstractProcessingHandler
@@ -103,28 +102,27 @@ protected function doWrite($record): void
103102
}
104103

105104
\Sentry\logger()->aggregator()->add(
106-
$this->getLevelFromMonologLevel($record['level']),
105+
// This seems a little bit of a roundabout way to get the log level, but this is done for compatibility
106+
self::getLogLevelFromSeverity(
107+
self::getSeverityFromLevel($record['level'])
108+
),
107109
$record['message'],
108110
[],
109111
array_merge($record['context'], $record['extra'])
110112
);
111113
}
112114

113-
private function getLevelFromMonologLevel(int $level): LogLevel
115+
private static function getLogLevelFromSeverity(Severity $severity): LogLevel
114116
{
115-
switch (Level::from($level)) {
116-
case Level::Debug:
117+
switch ($severity) {
118+
case Severity::debug():
117119
return LogLevel::debug();
118-
case Level::Warning:
120+
case Severity::warning():
119121
return LogLevel::warn();
120-
case Level::Error:
122+
case Severity::error():
121123
return LogLevel::error();
122-
case Level::Critical:
123-
case Level::Alert:
124-
case Level::Emergency:
124+
case Severity::fatal():
125125
return LogLevel::fatal();
126-
case Level::Info:
127-
case Level::Notice:
128126
default:
129127
return LogLevel::info();
130128
}

0 commit comments

Comments
 (0)