1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace RenePardon\GelfSupport; |
4
|
|
|
|
5
|
|
|
use Gelf\Publisher; |
6
|
|
|
use Gelf\Transport\UdpTransport; |
7
|
|
|
use Illuminate\Config\Repository; |
8
|
|
|
use Illuminate\Contracts\Debug\ExceptionHandler; |
9
|
|
|
use Illuminate\Support\ServiceProvider; |
10
|
|
|
use RenePardon\GelfSupport\Commands\TestLogging; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class GelfSupportServiceProvider |
14
|
|
|
* |
15
|
|
|
* @package renepardon\GelfSupport |
16
|
|
|
*/ |
17
|
|
|
class GelfSupportServiceProvider extends ServiceProvider |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var array |
21
|
|
|
*/ |
22
|
|
|
protected $commands = [ |
23
|
|
|
TestLogging::class, |
24
|
|
|
]; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Perform post-registration booting of services. |
28
|
|
|
* |
29
|
|
|
* @return void |
30
|
|
|
*/ |
31
|
|
|
public function boot() |
32
|
|
|
{ |
33
|
|
|
$this->publishes([ |
34
|
|
|
__DIR__ . '/../config/gelfsupport.php' => config_path('gelfsupport.php'), |
35
|
|
|
], 'config'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Register any package services. |
40
|
|
|
* |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
|
|
public function register() |
44
|
|
|
{ |
45
|
|
|
$config = $this->app->make(Repository::class); |
46
|
|
|
|
47
|
|
|
$this->commands($this->commands); |
48
|
|
|
|
49
|
|
|
$this->app->alias(ExceptionHandler::class, 'exceptions'); |
50
|
|
|
$this->app->singleton('exceptions.repository', ExceptionHandlerRepository::class); |
51
|
|
|
$this->app->extend(ExceptionHandler::class, function ($handler, $app) use ($config) { |
52
|
|
|
return new Decorator($handler, $app['exceptions.repository'], $config); |
53
|
|
|
}); |
54
|
|
|
|
55
|
|
|
$this->app->singleton(Graylog::class, function ($app) use ($config) { |
|
|
|
|
56
|
|
|
$transport = new UdpTransport( |
57
|
|
|
$config->get('gelfsupport.host'), |
58
|
|
|
$config->get('gelfsupport.port'), |
59
|
|
|
UdpTransport::CHUNK_SIZE_LAN |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
// While the UDP transport is itself a publisher, we wrap it in a real Publisher for convenience. |
63
|
|
|
// A publisher allows for message validation before transmission, and also supports sending |
64
|
|
|
// messages to multiple backends at once. |
65
|
|
|
$publisher = new Publisher(); |
66
|
|
|
$publisher->addTransport($transport); |
67
|
|
|
|
68
|
|
|
return new Graylog($publisher, 'gelf-php'); |
69
|
|
|
}); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.