Created
September 29, 2016 14:57
-
-
Save cviebrock/882df789d874ee9e7e316222cc00364f to your computer and use it in GitHub Desktop.
Log Laravel to Elastic/Logstash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace App\Providers; | |
use Elastica\Client; | |
use Illuminate\Support\ServiceProvider; | |
use Monolog\Formatter\LogstashFormatter; | |
use Monolog\Handler\ElasticSearchHandler; | |
class ElasticLoggingProvider extends ServiceProvider | |
{ | |
/** | |
* Register the service provider. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
$config = $this->app->make('config'); | |
$monolog = $this->app->make('log')->getMonolog(); | |
$client = new Client([ | |
'servers' => [ | |
[ | |
'host' => 'localhost', // eventually pull this from config/env | |
'port' => 9200, | |
], | |
], | |
]); | |
$handler = new ElasticSearchHandler($client); | |
$handler->setFormatter(new LogstashFormatter($config->get('app.env'))); | |
$monolog->pushHandler($handler); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment