Skip to content

Instantly share code, notes, and snippets.

@ariews
Created November 19, 2015 08:10
Show Gist options
  • Save ariews/978eba767f92fbb923d6 to your computer and use it in GitHub Desktop.
Save ariews/978eba767f92fbb923d6 to your computer and use it in GitHub Desktop.
Laravel 5.1 Papertrail
<?php
# file: config/app.php
return [
// ...
'providers' => [
//...
App\Providers\PapertrailServiceProvider::class,
//...
],
//...
];
<?php
# file config/papertrail.php
return [
'only' => env('PAPERTRAIL_ONLY', 'local'),
'host' => env('PAPERTRAIL_HOST'),
'port' => env('PAPERTRAIL_PORT'),
];
<?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