Created
November 19, 2015 08:10
-
-
Save ariews/978eba767f92fbb923d6 to your computer and use it in GitHub Desktop.
Laravel 5.1 Papertrail
This file contains 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 | |
# file: config/app.php | |
return [ | |
// ... | |
'providers' => [ | |
//... | |
App\Providers\PapertrailServiceProvider::class, | |
//... | |
], | |
//... | |
]; |
This file contains 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 | |
# file config/papertrail.php | |
return [ | |
'only' => env('PAPERTRAIL_ONLY', 'local'), | |
'host' => env('PAPERTRAIL_HOST'), | |
'port' => env('PAPERTRAIL_PORT'), | |
]; |
This file contains 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 | |
# file: app/Providers/PapertrailServiceProvider.php | |
namespace App\Providers; | |
use Illuminate\Log\Writer; | |
use Illuminate\Support\ServiceProvider; | |
use Monolog\Formatter\LineFormatter; | |
use Monolog\Handler\SyslogUdpHandler; | |
class PapertrailServiceProvider extends ServiceProvider | |
{ | |
public function register() | |
{ | |
$only = config('papertrail.only'); | |
$host = config('papertrail.host'); | |
$port = config('papertrail.port'); | |
if (app()->environment($only) && ((! empty($host) && $host != 'hostname'))) { | |
$mono = app(Writer::class)->getMonolog(); | |
$syslog = new SyslogUdpHandler($host, $port); | |
$syslog->setFormatter(new LineFormatter('%channel%.%level_name%: %message% %extra%', null, true)); | |
$mono->pushHandler($syslog); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment