read

Papertrail is an awesome way to store, manage and search both your server logs as well as your web app logs. They provide you with a nice realtime aggregated view of all your servers' logs and allow you to save searches so you don't have to repeat yourself over and over again.

Setting it up on any common web server is very simple and Papertrail will guide you through it

After the initial server setup, all it takes is following the rest of this article and you'll have your Laravel logs handled by Papertrail in no time!

Setting it up with Laravel 5

The best way I've found to send your Laravel logs to Papertrail is to create a new Service Provider:

php artisan make:provider PapertrailServiceProvider

And then simply add the following to the register() method:

public function register()
{
    if (app('app')->environment() == 'local') return;

    $monolog   = app(\Illuminate\Log\Writer::class)->getMonolog();
    $syslog    = new \Monolog\Handler\SyslogHandler('laravel');
    $formatter = new \Monolog\Formatter\LineFormatter('%channel%.%level_name%: %message% %extra%');

    $syslog->setFormatter($formatter);
    $monolog->pushHandler($syslog);
}

After you're done with your new Service Provider, you just have to reference it in your config/app.php file within the providers array:

'providers' => [
    ...,
    App\Providers\PapertrailServiceProvider::class,
]

You're all set. Your logs are now being automatically pushed up to Papertrail!

Blog Logo

Rui Gomes

Web Developer, Internet Marketing enthusiast and Student@FEUP. That pretty much sums it up.


Published

Image

Rui Gomes

Knowledge share with a great deal of random thoughts.

Back to Overview