Cloudflare Docs
Logs
Logs
Edit this page on GitHub
Set theme to dark (⇧+D)

Enable 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 whether retention is on
  • POST /logs/control/retention/flag - turns retention on or off

​​ Example API requests using cURL

​​ Check whether log retention is turned on:

$ curl -s -H "X-Auth-Email: <EMAIL>" -H "X-Auth-Key: <API_KEY>" GET "https://api.cloudflare.com/client/v4/zones/<ZONE_ID>/logs/control/retention/flag" | jq .

​​ Response:

{
"errors": [],
"messages": [],
"result": {
"flag": false
},
"success": true
}

​​ Turn on log retention:

On Linux or macOS:

curl -s -H "X-Auth-Email: <EMAIL>" -H "X-Auth-Key: <API_KEY>" POST "https://api.cloudflare.com/client/v4/zones/<ZONE_ID>/logs/control/retention/flag" -d'{"flag":true}' | jq .

On Windows in Command Prompt:

curl.exe -s -H "X-Auth-Email: <EMAIL>" -H "X-Auth-Key: <API_KEY>" POST "https://api.cloudflare.com/client/v4/zones/<ZONE_ID>/logs/control/retention/flag" -d "{""flag"":true}"

For further help with API calls on Windows, refer to Making API calls on Windows.

​​ Parameters

  • flag - can be either true or false

​​ Response:

{
"errors": [],
"messages": [],
"result": {
"flag": true
},
"success": true
}

​​ Audit

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