Skip to content

Commit a360980

Browse files
patrickbrouwersstayallive
authored andcommitted
Add support for laravel 5.6 log channels (#122)
* Add support for laravel 5.6 log channels * Update SentryLaravelServiceProvider.php * Update SentryLaravelServiceProvider.php * Rename to SentryLogChannel * Rename to SentryLogChannel * Rename CreateSentryLogChannel.php to SentryLogChannel.php * Fix phpcs not liking PHP 7 features
1 parent 33ec181 commit a360980

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/Sentry/SentryLaravel/SentryLaravelServiceProvider.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ public function register()
100100

101101
return $client;
102102
});
103+
104+
$app = $this->app;
105+
106+
// Add a sentry log channel for Laravel 5.6+
107+
if (version_compare($app::VERSION, '5.6') >= 0) {
108+
$this->app->make('log')->extend('sentry', function ($app, array $config) {
109+
$channel = new SentryLogChannel($app);
110+
return $channel($config);
111+
});
112+
}
103113
}
104114

105115
/**
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Sentry\SentryLaravel;
4+
5+
use Illuminate\Log\LogManager;
6+
use Monolog\Handler\RavenHandler;
7+
use Monolog\Logger;
8+
9+
class SentryLogChannel extends LogManager
10+
{
11+
/**
12+
* @param array $config
13+
*
14+
* @return Logger
15+
*/
16+
public function __invoke(array $config)
17+
{
18+
$handler = new RavenHandler(
19+
$this->app->make('sentry'),
20+
isset($config['level']) ? $config['level'] : null,
21+
isset($config['bubble']) ? $config['bubble'] : true
22+
);
23+
24+
return new Logger($this->parseChannel($config), [$this->prepareHandler($handler)]);
25+
}
26+
}

0 commit comments

Comments
 (0)