Laravel Forge - Logging With Papertrail
Posted on May 16, 2014 | By Matt Stauffer
(This is part of a series of posts on Laravel Forge. )
- Getting your first site up and running in Laravel Forge
- Laravel Forge - Logging With Papertrail
- Laravel Forge - Using Environment Variables for Environment Detection
- Laravel Forge - Adding a Queue Worker with Beanstalkd
- Laravel Forge - Scheduling a Cron Job
- Laravel Forge - Adding an SSL Cert
- Laravel Forge - Password Protect a Folder
- Laravel Forge - Wildcard Subdomains
- Laravel Forge - Using Recipes
- Laravel Forge - Hosting on AWS
- Laravel Forge - Forge Plus and Circles
- Laravel Forge - Fixing the CVE-2014-6271 Bash Vulnerability
- Laravel Forge - Global Recipes & the FastCGI Nginx Update
- Starting a blog with Sculpin on Laravel Forge
- Installing a fresh Craft CMS Installation 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
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
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