Netlify Log Drains allow you to export your Netlify site’s logs to external logging platforms, giving you deeper insights and better control over your application’s behavior.

Let’s see how this works with a live example. Imagine you have a Next.js application deployed on Netlify. When users interact with your site, Netlify generates various logs: build logs, deploy logs, and runtime logs (from functions and edge functions). By default, these logs are only accessible through the Netlify UI.

With Log Drains, you can configure Netlify to send these logs to platforms like Datadog or Splunk. Here’s a simplified view of a Netlify deploy log, which you might see in the UI:

Deploy logged
──────────────────────────────────────────────────
  URL: https://your-site-name.netlify.app
  Build ID: a1b2c3d4e5f678901234567890abcdef
  Commit: abcdef1234567890abcdef1234567890
  Status: succeeded
  --------------------------------------------------
  Timestamp: 2023-10-27T10:00:00Z
  Message: Build finished. Deploying to production.

Now, if you set up a Log Drain to Datadog, this information, along with detailed build steps and any errors, would be streamed to your Datadog account. In Datadog, you could then create dashboards to monitor build success rates, track deployment times, and set up alerts for failed builds.

The problem Netlify Log Drains solve is the inherent limitation of centralized, UI-bound logging. For complex applications, distributed systems, or teams requiring advanced log analysis, relying solely on the Netlify UI becomes inefficient. You can’t easily correlate Netlify logs with logs from other services, perform complex queries across historical data, or set up sophisticated alerting that goes beyond basic email notifications.

Internally, Netlify Log Drains operate by creating an HTTP endpoint on your chosen logging platform. Netlify then POSTs log events to this endpoint as they occur. These events are typically formatted as JSON payloads.

Here’s how you configure it in Netlify:

  1. Navigate to your Site Settings: In your Netlify dashboard, go to your site’s "Site settings."
  2. Find "Log drains": Under the "General" section, you’ll find "Log drains."
  3. Add a new drain: Click "Add log drain."
  4. Choose your provider: Select "Datadog" or "Splunk" (or "Other" for custom integrations).
  5. Configure the endpoint:
    • Datadog: You’ll need your Datadog API key and a specific endpoint URL (e.g., https://http-intake.logs.datadoghq.com/api/v2/logs).
    • Splunk: You’ll need your Splunk HTTP Event Collector (HEC) token and the HEC URL (e.g., https://your-splunk-instance.splunkcloud.com:8088/services/collector).
  6. Select log types: Choose which logs you want to send: "Build logs," "Deploy logs," "Edge logs," and "Function logs."
  7. Save and test: Save the configuration. Netlify will send a test log to verify the connection.

The exact levers you control are the log types you choose to send and the configuration of the destination endpoint. For example, in Datadog, you might tag these logs with service:netlify and environment:production to easily filter and group them alongside other application logs.

The most surprising true thing about Netlify Log Drains is that they don’t just send what happened, but also when and how. Each log event is a rich JSON object containing not just the message, but also metadata like the site name, deploy ID, build ID, function name, and even the specific file and line number for build failures. This granular detail is crucial for debugging, as it allows you to pinpoint the exact moment and context of an issue, rather than just seeing a generic error message.

Once you have your logs flowing, the next logical step is to leverage this data for proactive monitoring and alerting.

Want structured learning?

Take the full Netlify course →