Enable Logpush to Cloudflare R2
Cloudflare Logpush supports pushing logs directly to R2 via the Cloudflare dashboard or via API.
For more information about R2, refer to the Cloudflare R2 documentation.
Before getting started:
Create an R2 bucket and set up R2 API tokens.
Go to the R2 UI > Create bucket.
Select Manage R2 API Tokens.
Select Create API token.
Under Permission, select Edit permissions for your token.
Copy the Secret Access Key and Access Key ID. You will need these when setting up your Logpush job.
Ensure that you have the following permissions:
- R2 write, Logshare Edit.
Manage via the Cloudflare dashboard
Enable Logpush to R2 via the dashboard.
Log in to the Cloudflare dashboard.
Select the Enterprise account or domain you want to use with Logpush.
Go to Analytics & Logs > Logs.
Select Add Logpush job.
In Select data set, choose the dataset to push to a storage service, and select Next.
In Select data fields:
- Select the data fields to include in your logs. Add or remove fields later by modifying your settings in Logs > Logpush.
- In Advanced Settings, you can change the Timestamp format (
RFC3339
(default),Unix
, orUnixNano
), Sampling rate and enable redaction forCVE-2021-44228
. - Under Filters you can select the events to include and/or remove from your logs. For more information, refer to Filters. Not all datasets have this option available.
In Select a destination, choose R2 Object Storage.
Enter the following destination information:
- Bucket path, for example,
cloudflare-logs/http_requests/example.com
- R2 access key ID
- R2 secret access key
- Bucket path, for example,
Select Validate access.
Select Save and Start Pushing to finish enabling the Logpush job.
Manage via API
To create a job, make a POST
request to the Logpush jobs endpoint with the following fields:
- name (optional) - Use your domain name as the job name.
- destination_conf - A log destination consisting of bucket path, account ID, R2 access key ID and R2 secret access key.
r2://<BUCKET_PATH>/{DATE}?account-id=<ACCOUNT_ID>&access-key-id=<R2_ACCESS_KEY_ID>&secret-access-key=<R2_SECRET_ACCESS_KEY>
- dataset - The category of logs you want to receive. Refer to Log fields for the full list of supported datasets.
- logpull_options (optional) - To configure fields, sample rate, and timestamp format, refer to API configuration options.
Example request using cURL:
curl -X POST 'https://api.cloudflare.com/client/v4/zones/<ZONE_ID>/logpush/jobs' \
-H 'X-Auth-Key: <API_KEY>' \
-H 'X-Auth-Email: <EMAIL>' \
-H 'Content-Type: application/json' \
-d '{"name": "<DOMAIN_NAME>","logpull_options": "fields=ClientIP,ClientRequestHost,ClientRequestMethod,ClientRequestURI,EdgeEndTimestamp,EdgeResponseBytes,EdgeResponseStatus,EdgeStartTimestamp,RayID×tamps=rfc3339","destination_conf": "r2://<BUCKET_PATH>/{DATE}?account-id=<ACCOUNT_ID>&access-key-id=<R2_ACCESS_KEY_ID>&secret-access-key=<R2_SECRET_ACCESS_KEY>","dataset": "http_requests","enabled": true}'| jq .