- Fastly Status
Useful conditions for logging
Last updated October 30, 2017
Logging errors only
You can log errors only if you want a general purpose log that catches everything and a more detailed log if there’s an error:
fastly_info.state == "ERROR"
You can also log only 500 errors:
resp.status >= 500 && resp.status < 600
Logging only specific URLs using an Edge Dictionary
Using an Edge Dictionary (e.g.,
urls_to_log), you can log specific URLs having issues:
table.lookup(urls_to_log, req.url.path) == "log"
If a URL becomes a problem, you can start logging it by using the API to add the URL's path to the dictionary as a key with the value "log".
If you have a high-volume service, you might want to log only a proportion of requests by using the
randombool VCL function in a condition. The following example will log only one percent of all requests:
You could combine that with an Edge Dictionary to change the percentage of requests logged without having to deploy a new version of your service. The following example uses an Edge Dictionary named
randombool(std.atoi(table.lookup(service_variables, "logging_percentage", 0)), 100)
In the example above, if the key
logging_percentage doesn't exist, nothing will be logged.
Using !req.url to construct a log string in custom VCL
If you want to construct a log string in custom VCL, you can use the
!req.url condition. This condition never evaluates to true, so nothing is sent to Fastly logging objects. Instead, it ensures that the log statement is generated in your custom VCL.