Skip to content

Commit 1bb2c52

Browse files
committed
Added updates for Laravel 10 only (PHP 8.1 and illuminate/support 10) and updated the handler to use the new interface
1 parent 27b93b3 commit 1bb2c52

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
}
2323
],
2424
"require": {
25-
"php": ">=7.2|^8.0",
26-
"illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0",
25+
"php": "^8.1",
26+
"illuminate/support": "^10.0",
2727
"rollbar/rollbar": "^2.0 | ^3.1"
2828
},
2929
"require-dev": {

src/MonologHandler.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,41 @@
33
namespace Rollbar\Laravel;
44

55
use Monolog\Handler\RollbarHandler;
6+
use Monolog\LogRecord;
67

78
class MonologHandler extends RollbarHandler
89
{
910
protected $app;
1011

12+
/**
13+
* @param $app
14+
* @return void
15+
*/
1116
public function setApp($app)
1217
{
1318
$this->app = $app;
1419
}
1520

16-
protected function write(array $record): void
21+
/**
22+
* @param LogRecord $record
23+
* @return void
24+
*/
25+
protected function write(LogRecord $record): void
1726
{
18-
$record['context'] = $this->addContext($record['context']);
19-
parent::write($record);
27+
parent::write(new LogRecord($record->datetime,
28+
$record->channel,
29+
$record->level,
30+
$record->message,
31+
(array_merge($record->toArray(), [ 'context' => $this->addContext($record->context) ])),
32+
$record->extra,
33+
$record->formatted));
2034
}
2135

2236
/**
23-
* Add Laravel specific information to the context.
24-
*
2537
* @param array $context
38+
* @return array
2639
*/
27-
protected function addContext(array $context = [])
40+
protected function addContext(array $context = []): array
2841
{
2942
$config = $this->rollbarLogger->extend([]);
3043

@@ -47,7 +60,7 @@ protected function addContext(array $context = [])
4760
} elseif (method_exists($data, 'getKey')) {
4861
$person['id'] = $data->getKey();
4962
}
50-
63+
5164
if (isset($person['id'])) {
5265
if (isset($data->username)) {
5366
$person['username'] = $data->username;

0 commit comments

Comments
 (0)