# How to send Laravel Vapor logs to Papertrail

As a serverless application, [Ymir](https://ymirapp.com) runs on [Laravel Vapor](https://vapor.laravel.com/). (Yes, a serverless WordPress platform runs on a serverless Laravel platform. Very meta lol.) Laravel Vapor is such an amazing service, and it's why I built Ymir. But there are a few rough spots and one of them is logging.

# CloudWatch is terrible for monitoring logs

If you ask around, you'll find that most people who output logs on Vapor send them to [CloudWatch](https://aws.amazon.com/cloudwatch/). You can do that using the `stderr` channel. [Lambda](https://aws.amazon.com/lambda/) will pick up everything sent to the error log and send it to CloudWatch. The problem with this solution is that CloudWatch isn't a very good platform for working with logs. In fact, it's pretty terrible. It's hard to get a feed of all your Lambda logs to work with. At least, I never really figured out a good way to do it. That's why Ymir didn't really have any logging. It just had error monitoring with [Sentry](https://sentry.io/). Error monitoring is great and necessary, but it doesn't quite solve the same problem logging does. (Although there's some overlap.) But there's good logging software and one of them is [Papertrail](https://www.papertrail.com/). Laravel even has a channel for it by default. That's how popular it is. # Papertrail is great, but doesn't work with UDP

Unfortunately, when asking around, no one could get Papertrail to work with Laravel Vapor. That's because Lambda blocks [UDP](https://en.wikipedia.org/wiki/User_Datagram_Protocol) and that's how you send your logs to Papertrail *by default*. I highlight the default because almost everyone (myself included) thought this was the only way to send logs to Papertrail. It's not. You can send them via [TCP](https://en.wikipedia.org/wiki/Transmission_Control_Protocol). Something [my friend Shawn wrote about](https://shawnhooper.ca/2019/11/17/logging-laravel-to-papertrail-on-platform-sh/) a few years ago. He was trying to get Papertrail to work with [Platform.sh](https://platform.sh/), but they also block UDP. He ended up finding out that you could send it via TCP. # Configuring Laravel to send logs to Papertrail using TCP

In his article, Shawn created a new logger class to send his logs to Papertrail. You actually don't even need to do that. You can just make some changes to the default `papertrail` log channel in your `logging.php` configuration file. ```
<?php

# config/logging.php

use Monolog\Handler\SocketHandler;

return [

    // ...

    'channels' => [

        // ...

        'papertrail' => [
            'driver' => 'monolog',
            'level' => 'debug',
            'handler' => SocketHandler::class,
            'handler_with' => [
                'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'),
            ],
        ],

        // ...

    ],

];

```

Here's the configuration you need to use. Instead of the [monolog](https://github.com/Seldaek/monolog) `SyslogUdpHandler`, you want to use the `SocketHandler`. You then replace the `handler_with` with the connection string used for TCP connections. You still use the same two papertrail environment variables as before. ![](https://carlalexander.ca/uploads/2021/08/papertrail-tcp.png)On the Papertrail side, you just need to make sure that your log destination accepts TLS encrypted connections over TCP. As you can see above, this is just a checkbox in the Papertrail admin. # Sweet sweet logs

So that's it! With this, you’ll finally be able to view your Laravel Vapor logs in an application that makes them useable. The only thing left is to generate useful logs to view. (Another challenging problem in itself!)