Laravel Forge - Logging With Papertrail
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.
Step 3: Sync
Paste this value into your Forge Monitoring tab. Wait for it to provision--this should just take a few minutes.
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.
Comments? I'm @stauffermatt on Twitter
Tags: forge • laravel • papertrail
This is part of a series of posts on Laravel Forge:
-
May 15, 2014 | laravel, forge
-
May 16, 2014 | forge, laravel, papertrail
-
May 19, 2014 | laravel, forge, environment
-
May 23, 2014 | laravel, forge, queue, beanstalkd
-
Jun 2, 2014 | laravel, forge, cron
-
Jun 2, 2014 | forge, laravel, ssl
-
Jun 17, 2014 | forge, htpasswd, nginx
-
Jun 23, 2014 | laravel, forge, subdomains
-
Jul 9, 2014 | forge, laravel, recipes
-
Jul 25, 2014 | laravel, forge, aws, hosting
-
Sep 17, 2014 | laravel, forge
-
Sep 24, 2014 | laravel, forge
-
Sep 25, 2014 | laravel, forge, recipes
-
Dec 24, 2014 | forge, sculpin, fiveMinuteGeekShow
-
Dec 29, 2014 | laravel, forge, craft