May 16, 2014 | forge, laravel, papertrail

Laravel Forge - Logging With Papertrail

Series

This is a series of posts on Laravel Forge.

!
Warning: This post is over a year old. I don't always update old posts with new information, so some of this information may be out of date.

If you're up and running with a Laravel Forge server, you can monitor your app's logs using the traditional Laravel log functionality, and you can also SSH in and tail your log files manually.

Note: Forge's Papertrail option is no longer baked in to the UI, but it's still possible to manually connect your Forge servers to Papertrail.

But Forge has a pre-built connection with an app called Papertrail that takes all of your logs and pulls them into one, easy-to-view SAAS. And it's painfully easy to set up.

Step 1: Get your Forge server up and running

Sign up for Forge. Get your server up and running. Go to the Server page and click the Monitoring tab.

Step 2: Sign up for Papertrail

Sign up at papertrailapp.com and navigate to the Setup Systems page. Grab the "your systems will log to" URL and copy it.

Get Papertrail URL

Step 3: Sync

Paste this value into your Forge Monitoring tab. Wait for it to provision--this should just take a few minutes.

Paste Papertrail URL

Step 4: Add a syslog handler

At this point Papertrail is logging your system logs, but not your Laravel logs. To add Laravel logs, you'll need to add a Syslog Monolog handler.

This would be best in a service provider, but if you just want to test it out you can put at the top of app/routes.php.

We're basically going to create a new Syslog handler for Monolog and push it onto the logging stack.

$monolog = Log::getMonolog();
$syslog = new \Monolog\Handler\SyslogHandler('papertrail');
$formatter = new \Monolog\Formatter\LineFormatter('%channel%.%level_name%: %message% %extra%');
$syslog->setFormatter($formatter);

$monolog->pushHandler($syslog);

As you can see, we're creating a syslog handler, naming it, providing it a formatter template (which you can customize to your liking), and then pushing it on the monolog handler stack.

Step 5: Profit

Go back to your Papertrail account and view your logs. That's it! Try throwing an exception in your code to see your Laravel logs show up in your Papertrail account.

Papertrail preview


Comments? I'm @stauffermatt on Twitter


Tags: forge  •  laravel  •  papertrail


This is part of a series of posts on Laravel Forge:

  1. May 16, 2014 | forge, laravel, papertrail
  2. May 23, 2014 | laravel, forge, queue, beanstalkd
  3. Jun 2, 2014 | laravel, forge, cron
  4. Jun 2, 2014 | forge, laravel, ssl
  5. Jun 17, 2014 | forge, htpasswd, nginx
  6. Jun 23, 2014 | laravel, forge, subdomains
  7. Jul 9, 2014 | forge, laravel, recipes
  8. Jul 25, 2014 | laravel, forge, aws, hosting
  9. Sep 17, 2014 | laravel, forge
  10. Dec 24, 2014 | forge, sculpin, fiveMinuteGeekShow

Subscribe

For quick links to fresh content, and for more thoughts that don't make it to the blog.