# How to Enable and View Logs in Supabase

- Tool: Supabase
- Difficulty: Beginner
- Time required: 10-15 min
- Compatibility: Supabase (all plans, with limits on free tier), Dashboard access required
- Last updated: March 2026

## TL;DR

Supabase provides logs for API requests, PostgreSQL queries, Edge Functions, and Auth events through the Dashboard under the Logs section. Navigate to your project Dashboard and click Logs in the left sidebar to access API logs, Postgres logs, and Edge Function logs. You can filter by time range, status code, and path. For external monitoring, configure log drains to send logs to services like Datadog or Logflare.

## Accessing and Using Logs in the Supabase Dashboard

Supabase logs every API request, database query, Edge Function execution, and auth event. These logs are essential for debugging failed requests, monitoring performance, and auditing user activity. This tutorial shows you where to find each type of log in the Dashboard, how to filter them effectively, and how to set up external log drains for production monitoring.

## Before you start

- A Supabase project (free tier or above)
- Access to the Supabase Dashboard
- At least some API activity or Edge Function invocations to generate logs

## Step-by-step guide

### 1. Access the Logs section in the Dashboard

Navigate to your Supabase project Dashboard and click on Logs in the left sidebar. You will see several log categories: API Gateway, Postgres, Edge Functions, Auth, Storage, and Realtime. Each category shows logs from its respective service. The API Gateway logs are the most commonly used — they show every REST API request including status codes, paths, and response times.

```
# No code needed — access via Dashboard
# Dashboard > Logs (left sidebar)
# Categories:
#   - API Gateway: REST API requests (PostgREST, Auth, Storage)
#   - Postgres: Database query logs
#   - Edge Functions: Function execution logs
#   - Auth: Authentication events
#   - Storage: File operations
#   - Realtime: WebSocket connections
```

**Expected result:** The Logs section is visible in the Dashboard with multiple log categories.

### 2. Filter API Gateway logs by status code and path

API Gateway logs show every HTTP request to your Supabase project. Use the built-in filters to narrow down results. Filter by status code to find errors (4xx, 5xx), by path to isolate specific endpoints, and by time range to focus on a particular incident. You can also use the search bar for custom queries. Each log entry shows the method, path, status code, response time, and request metadata.

```
# Dashboard > Logs > API Gateway
# Common filters:
#   Status: 400, 401, 403, 404, 500
#   Method: GET, POST, PATCH, DELETE
#   Path: /rest/v1/todos, /auth/v1/token
#   Time: Last 1 hour, Last 24 hours, Custom range

# Example: Find all failed auth requests
# Filter: path contains '/auth/' AND status >= 400

# Example: Find slow API requests
# Sort by response time, look for > 1000ms
```

**Expected result:** Filtered logs show only the requests matching your criteria, making it easy to identify issues.

### 3. View Edge Function logs with console.log output

Edge Function logs capture everything your function writes to console.log(), console.error(), and console.warn(), plus execution metadata like duration, status, and memory usage. Go to Dashboard > Logs > Edge Functions to view them. You can filter by function name to isolate a specific function's output. These logs are essential for debugging deployed Edge Functions since you cannot attach a debugger to production.

```
// In your Edge Function, add logging:
Deno.serve(async (req) => {
  console.log('Request received:', req.method, req.url)

  try {
    const body = await req.json()
    console.log('Request body:', JSON.stringify(body))

    // Your logic here...
    const result = { success: true }

    console.log('Response:', JSON.stringify(result))
    return new Response(JSON.stringify(result), {
      headers: { 'Content-Type': 'application/json' },
    })
  } catch (err) {
    console.error('Function error:', err.message)
    return new Response(
      JSON.stringify({ error: err.message }),
      { status: 500, headers: { 'Content-Type': 'application/json' } }
    )
  }
})

// View output: Dashboard > Logs > Edge Functions
```

**Expected result:** Console.log output from your Edge Functions appears in the Dashboard logs with timestamps.

### 4. Check Postgres logs for query errors and slow queries

Postgres logs show database-level events including query errors, connection issues, and slow queries. Navigate to Dashboard > Logs > Postgres to view them. These logs are particularly useful for debugging RLS policy issues (queries that return empty results unexpectedly), migration failures, and performance problems. Look for ERROR severity entries to find query failures.

```
# Dashboard > Logs > Postgres
# What you will see:
#   - SQL errors with exact error message and query
#   - Connection pool events
#   - Slow query warnings (if logging is configured)
#   - Migration execution results

# Common Postgres errors in logs:
# ERROR: permission denied for table todos
#   → Missing RLS policy or GRANT
# ERROR: new row violates row-level security policy
#   → INSERT/UPDATE blocked by RLS WITH CHECK
# ERROR: relation "table_name" does not exist
#   → Table not created or wrong schema
```

**Expected result:** Postgres logs show database errors and events that help diagnose query and permission issues.

### 5. Configure log drains for external monitoring

For production applications, you may want to send logs to external monitoring services like Datadog, Logflare, or a custom webhook. Supabase supports log drains on Pro plans and above. Go to Dashboard > Settings > Log Drains to configure a destination. Log drains stream logs in real-time, allowing you to set up alerts, dashboards, and long-term log retention in your preferred monitoring tool.

```
# Dashboard > Settings > Log Drains (Pro+ plans)
# Supported destinations:
#   - HTTP endpoint (webhook)
#   - Datadog
#   - Logflare (built-in integration)

# Configuration steps:
# 1. Go to Dashboard > Settings > Log Drains
# 2. Click 'Add log drain'
# 3. Select destination type
# 4. Enter endpoint URL and authentication
# 5. Select which log sources to include
# 6. Save and verify logs are flowing

# For HTTP webhook, logs are POSTed as JSON:
# {
#   "event_message": "...",
#   "timestamp": 1234567890,
#   "metadata": { ... }
# }
```

**Expected result:** Logs are streaming to your external monitoring service in real-time.

## Complete code example

File: `edge-function-with-logging.ts`

```typescript
// Edge Function with structured logging for production debugging
// supabase/functions/process-order/index.ts

import { createClient } from 'npm:@supabase/supabase-js@2'

const corsHeaders = {
  'Access-Control-Allow-Origin': '*',
  'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
}

// Structured logger for consistent log format
function log(level: 'info' | 'warn' | 'error', message: string, data?: Record<string, unknown>) {
  const entry = {
    level,
    message,
    timestamp: new Date().toISOString(),
    ...data,
  }
  if (level === 'error') {
    console.error(JSON.stringify(entry))
  } else if (level === 'warn') {
    console.warn(JSON.stringify(entry))
  } else {
    console.log(JSON.stringify(entry))
  }
}

Deno.serve(async (req) => {
  if (req.method === 'OPTIONS') {
    return new Response('ok', { headers: corsHeaders })
  }

  const requestId = crypto.randomUUID()
  log('info', 'Request received', { requestId, method: req.method })

  try {
    const supabase = createClient(
      Deno.env.get('SUPABASE_URL')!,
      Deno.env.get('SUPABASE_ANON_KEY')!,
      { global: { headers: { Authorization: req.headers.get('Authorization')! } } }
    )

    const { data: { user } } = await supabase.auth.getUser()
    if (!user) {
      log('warn', 'Unauthorized request', { requestId })
      return new Response(
        JSON.stringify({ error: 'Unauthorized' }),
        { status: 401, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
      )
    }

    log('info', 'User authenticated', { requestId, userId: user.id })

    const body = await req.json()
    const { data, error } = await supabase
      .from('orders')
      .insert({ user_id: user.id, ...body })
      .select()
      .single()

    if (error) {
      log('error', 'Database insert failed', { requestId, error: error.message })
      return new Response(
        JSON.stringify({ error: error.message }),
        { status: 500, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
      )
    }

    log('info', 'Order created', { requestId, orderId: data.id })
    return new Response(
      JSON.stringify({ order: data }),
      { status: 201, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
    )
  } catch (err) {
    log('error', 'Unexpected error', { requestId, error: (err as Error).message })
    return new Response(
      JSON.stringify({ error: 'Internal server error' }),
      { status: 500, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
    )
  }
})
```

## Common mistakes

- **Not checking logs when API requests silently return empty results due to RLS** — undefined Fix: When queries return empty arrays unexpectedly, check Postgres logs for 'row-level security' messages. Empty results with no error usually mean RLS is blocking access.
- **Logging sensitive user data like passwords, tokens, or personal information in Edge Functions** — undefined Fix: Only log identifiers (user IDs, request IDs) and operational data. Redact or omit sensitive fields before logging. This prevents data leaks through log storage.
- **Ignoring Edge Function BOOT_ERROR entries in logs, which indicate import or syntax errors** — undefined Fix: BOOT_ERROR means the function failed to start, usually due to a bad import path or syntax error. Check the error message in the log entry and fix the import statement.

## Best practices

- Check API Gateway logs first when debugging frontend errors — they show the full server-side request and response
- Use structured JSON logging in Edge Functions for easier parsing and searching in external tools
- Include request IDs in your logs so you can trace a single request across multiple log entries
- Filter Postgres logs by ERROR severity to quickly find query failures and permission issues
- Set up log drains on Pro plans for real-time alerting on errors and performance degradation
- Avoid logging sensitive data — use user IDs and request IDs instead of full payloads
- Review Edge Function logs after deployment to catch BOOT_ERROR and TIME_LIMIT issues early

## Frequently asked questions

### How long are logs retained in Supabase?

Log retention depends on your plan. Free plan retains logs for 1 day. Pro plan retains logs for 7 days. For longer retention, configure log drains to send logs to an external service with your desired retention period.

### Can I search logs by a specific error message?

Yes. Use the search bar in the Logs section to search across log entries. You can search for error messages, paths, status codes, or any text that appears in the log entries.

### Why do I see empty Postgres logs?

Postgres logs may appear empty if no errors have occurred recently or if query logging is not enabled for your plan. API Gateway logs are more likely to show activity since they capture all HTTP requests.

### How do I see console.log output from Edge Functions?

Console.log, console.warn, and console.error output from Edge Functions appears in Dashboard > Logs > Edge Functions. Filter by function name to isolate a specific function's output.

### Are log drains available on the free plan?

No. Log drains are available on Pro plan and above. On the free plan, you can only view logs directly in the Dashboard with 1-day retention.

### Can I set up alerts based on log patterns?

Not directly in Supabase. Configure a log drain to send logs to a monitoring service like Datadog or PagerDuty, then set up alerts there based on error patterns, status codes, or response times.

### Can RapidDev help set up monitoring and logging for my Supabase project?

Yes. RapidDev can configure log drains, set up structured logging in your Edge Functions, create monitoring dashboards, and implement alerting for your Supabase production environment.

---

Source: https://www.rapidevelopers.com/supabase-tutorial/how-to-enable-logs-in-supabase
© RapidDev — https://www.rapidevelopers.com/supabase-tutorial/how-to-enable-logs-in-supabase
