Centralized logging service for Cloudflare Workers.
- Sharded storage - Each app gets isolated SQLite via Durable Objects
- Dual access - RPC binding for internal workers, REST API with API key for external
- Web dashboard - Browse and search logs at
/dashboard - Health monitoring - Periodic URL checks via DO alarms
- Daily stats - Aggregated log counts by level
- Result types - Ok/Err response format for consistency
Create a token at https://dash.cloudflare.com/profile/api-tokens using the "Edit Cloudflare Workers" template, then add:
- Workers KV Storage: Edit
- Account Settings: Read
Create a .env file with your credentials:
CLOUDFLARE_API_TOKEN=your-api-token
CLOUDFLARE_ACCOUNT_ID=your-account-idnpm install
npm run dev # Local development
npm run deploy # Deploy to Cloudflare (or use CI/CD)npm run wrangler -- kv namespace create LOGS_KV
# Add the returned ID to wrangler.jsoncnpm run wrangler -- secret put ADMIN_API_KEY
# Enter a secure random key (e.g., openssl rand -hex 24)Access the dashboard at /dashboard to browse and search logs. Requires admin key login.
# Write logs
curl -X POST https://worker-logs.<your-domain>.workers.dev/logs \
-H "X-App-ID: my-app" \
-H "X-Api-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{"level": "INFO", "message": "Hello from external"}'
# Query logs
curl "https://worker-logs.<your-domain>.workers.dev/logs?level=ERROR&limit=10" \
-H "X-App-ID: my-app" \
-H "X-Api-Key: your-api-key"
# Get daily stats
curl "https://worker-logs.<your-domain>.workers.dev/stats/my-app?days=7" \
-H "X-App-ID: my-app" \
-H "X-Api-Key: your-api-key"// In your worker's wrangler.jsonc:
// "services": [{ "binding": "LOGS", "service": "worker-logs", "entrypoint": "LogsRPC" }]
// Usage:
await env.LOGS.info('my-app', 'User action', { userId: '123' })
await env.LOGS.error('my-app', 'Something failed', { error: err.message })npm test # Run all tests
npm run test:watch # Watch mode- Integration Guide - How to integrate worker-logs into your workers
- Implementation Plan - Architecture and design details
MIT