Logs

Query structured logs for a specific mirror to monitor replication activity, debug issues, and track operational events.

Get Mirror Logs

Retrieve logs for a specific mirror with filtering and pagination.

Endpoint

GET /v1/mirrors/{name}/logs

Permission: authed (any authenticated user)

Path Parameters

ParameterTypeDescription
namestringUnique mirror name

Query Parameters

ParameterTypeDefaultDescription
limitnumber50Number of logs to return (max 500)
offsetnumber0Number of logs to skip (for pagination)
searchstring-Text search across log messages and details
levelstring-Filter by log level: INFO, WARN, ERROR, or DEBUG

Response

FieldTypeDescription
logsarrayArray of log entry objects
totalnumberTotal number of logs matching the filter
offsetnumberCurrent offset (for pagination)
limitnumberCurrent limit

Log Entry Object

FieldTypeDescription
idnumberUnique log entry ID
levelstringLog level (INFO, WARN, ERROR, DEBUG)
messagestringHuman-readable log message
detailsobjectAdditional structured data (varies by log type)
created_atstringISO 8601 timestamp

Example: Basic Request

curl http://localhost:8112/v1/mirrors/prod-to-analytics/logs \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Example: Filter by Log Level

Retrieve only error logs:

curl "http://localhost:8112/v1/mirrors/prod-to-analytics/logs?level=ERROR" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Search logs for specific content:

curl "http://localhost:8112/v1/mirrors/prod-to-analytics/logs?search=snapshot" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Example: Pagination

Retrieve the next page of logs:

curl "http://localhost:8112/v1/mirrors/prod-to-analytics/logs?limit=100&offset=100" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Example: Combine Filters

Filter by level and search term:

curl "http://localhost:8112/v1/mirrors/prod-to-analytics/logs?level=ERROR&search=connection" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Log Levels

BunnyDB logs use standard log levels:

LevelDescriptionUse Case
DEBUGDetailed diagnostic informationDevelopment, debugging complex issues
INFOGeneral informational messagesNormal operations, progress tracking
WARNWarning messages for non-critical issuesPotential problems, degraded performance
ERRORError messages for failuresFailed operations, exceptions, retries

In production, most logs are at the INFO level. Use ERROR level filtering to quickly identify issues requiring attention.

Common Log Messages

Snapshot Phase

MessageLevelDescription
Starting initial snapshotINFOSnapshot phase beginning
Table snapshot completedINFOIndividual table snapshot finished
Initial snapshot completedINFOAll tables snapshotted successfully
Snapshot failedERRORSnapshot encountered an error

CDC Phase

MessageLevelDescription
CDC batch fetched from sourceINFOChanges retrieved from WAL
CDC batch applied successfullyINFOChanges written to destination
No changes in CDC batchINFONo new changes since last poll
Failed to apply CDC batchERRORError applying changes

Control Operations

MessageLevelDescription
Mirror pausedINFOMirror paused via API
Mirror resumedINFOMirror resumed via API
Schema sync initiatedINFOSchema sync started
Table resync startedINFOIndividual table resync started
Retry signal receivedINFORetryNow signal processed

Errors and Warnings

MessageLevelDescription
Replication slot already existsERRORSlot conflict from previous run
Connection timeoutERRORCannot connect to database
Heartbeat timeoutERRORActivity not responding
Foreign key violationWARNFK constraint temporarily violated

Using Logs for Monitoring

Check Recent Activity

View the last 10 logs to see what’s happening now:

curl "http://localhost:8112/v1/mirrors/my-mirror/logs?limit=10" \
  -H "Authorization: Bearer <token>"

Identify Recent Errors

Find recent errors for troubleshooting:

curl "http://localhost:8112/v1/mirrors/my-mirror/logs?level=ERROR&limit=20" \
  -H "Authorization: Bearer <token>"

Track Snapshot Progress

Search for snapshot-related logs:

curl "http://localhost:8112/v1/mirrors/my-mirror/logs?search=snapshot" \
  -H "Authorization: Bearer <token>"

Monitor CDC Throughput

Search for batch application logs to see throughput:

curl "http://localhost:8112/v1/mirrors/my-mirror/logs?search=batch+applied" \
  -H "Authorization: Bearer <token>"

Details Object Structure

The details field contains structured data specific to each log type. Common fields include:

CDC Batch Logs

{
  "batch_id": 42,
  "rows_processed": 1250,
  "rows_inserted": 500,
  "rows_updated": 600,
  "rows_deleted": 150,
  "duration_ms": 324,
  "lsn": "0/1A2B3C4D",
  "tables_affected": ["public.users", "public.orders"]
}

Snapshot Logs

{
  "table": "public.users",
  "rows_snapshotted": 150000,
  "duration_seconds": 45,
  "partition": 3,
  "total_partitions": 5
}

Error Logs

{
  "error": "pq: connection refused",
  "retry_count": 3,
  "next_retry_at": "2024-01-15T12:40:00Z",
  "operation": "apply_cdc_batch"
}

Schema Sync Logs

{
  "tables": ["public.users", "public.orders"],
  "ddl_statements": [
    "ALTER TABLE users ADD COLUMN email_verified BOOLEAN"
  ],
  "duration_ms": 150
}

Pagination Best Practices

For large log sets, use pagination to retrieve all logs efficiently:

# Get first page
curl "http://localhost:8112/v1/mirrors/my-mirror/logs?limit=500&offset=0" \
  -H "Authorization: Bearer <token>"
 
# Get next page
curl "http://localhost:8112/v1/mirrors/my-mirror/logs?limit=500&offset=500" \
  -H "Authorization: Bearer <token>"
 
# Continue until offset >= total

The maximum limit is 500. For retrieving large log sets, use multiple requests with increasing offset values.

Integration with Monitoring

Logs can be integrated into external monitoring and alerting systems:

Alert on Errors

Poll for new error logs every minute:

curl "http://localhost:8112/v1/mirrors/my-mirror/logs?level=ERROR&limit=10" \
  -H "Authorization: Bearer <token>"

If new errors appear since last check, trigger an alert.

Track Throughput Metrics

Extract rows_processed and duration_ms from CDC batch logs to calculate:

  • Rows per second: rows_processed / (duration_ms / 1000)
  • Average batch size
  • Replication lag based on timestamps

Monitor Replication Health

Look for these patterns:

  • Healthy: Regular “CDC batch applied successfully” logs
  • Stalled: No logs for extended period
  • Degraded: Increasing error count or retry messages
  • Failed: Repeated errors with same error message

For comprehensive monitoring strategies, see the Monitoring page.