Setting Up PaperTrail for a Flask App on DigitalOcean

I’ve been running a Flask app on DigitalOcean that processes receipts sent via email and adds them to Airtable. While DigitalOcean provides basic live logging, it’s mostly useful for real-time debugging and doesn’t store logs for later use. To get more robust log storage and analysis, I decided to integrate PaperTrail, a beginner-friendly logging service. Here’s how I set it up.


Why Use PaperTrail?

PaperTrail (and similar services like Logtail or Datadog) allows you to:

  • Store Logs: Keep logs accessible for troubleshooting later.
  • Search & Filter: Find specific log entries easily (some features depend on your plan).
  • Set Alerts: Notify you when certain events occur.
  • Centralize Logs: Collect logs from multiple apps and servers in one place.

This makes it a step up from DigitalOcean’s live logging, which is primarily for real-time viewing.


Steps to Set Up PaperTrail for Your DigitalOcean Flask App

1. Set Up the Logging Service in DigitalOcean

  1. Navigate to SaaS Add-ons in your DigitalOcean dashboard.
  2. Find PaperTrail and click Add PaperTrail.
  3. Choose a plan:
    • I started with the free plan, which is great for experimenting (note: it doesn’t include log search).
  4. Agree to the PaperTrail terms by checking the box.
  5. Click Add PaperTrail to enable the service.

2. Create a Free Account on PaperTrail

  • After enabling the service in DigitalOcean, you’ll be redirected to PaperTrail’s website.
  • Create a free account or log in if you already have one.

3. Create Your First System Event on PaperTrail

  1. In PaperTrail’s dashboard, click Add Systems.
  2. Follow the steps to create a new system event.

This will give you an endpoint in the format:

logs.papertrailapp.com:12345

4. Configure Log Forwarding for Your DigitalOcean App

Now it’s time to connect your Flask app's logs to PaperTrail.

  1. Go back to your DigitalOcean dashboard and navigate to your app.
  2. Click on Settings and locate the Log Forwarding section.
  3. Click Edit and choose PaperTrail from the list of providers.
  4. Fill out the following fields:
    • Destination Name: Any name you like (e.g., "FlaskApp Logs").
    • Endpoint: Paste the endpoint you got from PaperTrail in Step 3.
  5. Select the logs you want to forward:
    • I chose Forward logs from all compute resources to ensure everything gets logged.
  6. Click Add Log Destination.

5. Test the Setup

  • Visit your PaperTrail dashboard. It should show a message indicating that it’s receiving log events.
  • Fire up your Flask app and check the logs in PaperTrail. You’ll see the logs being forwarded in real-time.

Additional Tips:

  • Test Log Events: Trigger a few log events in your app to ensure everything works as expected.
  • Upgrade Plans (Optional): If you need advanced features like searching through logs, consider upgrading to a paid plan.

Wrapping Up

That’s it! You’ve now set up PaperTrail logging for your Flask app hosted on DigitalOcean. Logs are no longer stuck on your server or limited to live debugging—they’re centralized, accessible, and easy to analyze. Whether you’re tracking errors or monitoring app performance, this setup makes life so much easier. 🎉