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 MonologHandlerSyslogHandler('papertrail'); $formatter = new MonologFormatterLineFormatter('%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.
Source link https://mattstauffer.com/blog/laravel-forge-logging-with-papertrail