Skip to content

Enabling log retention

By default, your HTTP request logs are not retained. When using the Logpull API for the first time, you will need to enable retention. You can also turn off retention at any time. Note that after retention is turned off, previously saved logs will be available until the retention period expires (refer to Data retention period).

Endpoints

There are two endpoints for managing log retention:

  • GET /logs/control/retention/flag - returns the current status of retention
  • POST /logs/control/retention/flag - turns retention on or off

Example API requests using cURL

Check log retention status

Terminal window
curl https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag \
--header "Authorization: Bearer <API_TOKEN>"

If the zone has log retention enabled you get the value true, whereas a value of false is returned when it is disabled.

Turn on log retention

Terminal window
curl https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{"flag": true}'

Enabled response

{
"flag": true
}

Turn off log retention

Terminal window
curl https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{
"flag": false
}'

Disabled response

{
"flag": false
}

Audit

Turning log retention on or off is recorded in Cloudflare Audit Logs.