---
title: Useful conditions for logging
summary: null
url: >-
  https://www.fastly.com/documentation/guides/integrations/streaming-logs/useful-conditions-for-logging
---


In addition to the [standard logging directives](/guides/integrations/streaming-logs/custom-log-formats), the following [conditions](/guides/full-site-delivery/conditions/about-conditions) can be used for logging when you set up [remote log streaming](/guides/integrations/streaming-logs/setting-up-remote-log-streaming).

> **IMPORTANT:** <Partial name='gdpr-logging-privacy' inline />

## 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:

```vcl
fastly_info.state == "ERROR"
```

You can also log only 500 errors:

```vcl
resp.status >= 500 && resp.status < 600`
```

## Logging only specific URLs using a dictionary

Using a [dictionary](/guides/full-site-delivery/dictionaries/about-dictionaries) (e.g., `urls_to_log`), you can log specific URLs having issues:

```vcl
table.lookup(urls_to_log, req.url.path) == "log"
```

If a URL becomes a problem, you can start logging it by using [the API](/reference/api/dictionaries/dictionary-item/) to add the URL's path to the dictionary as a key with the value "log".

## Logging samples

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:

```vcl
randombool(1,100)
```

You could combine that with a [dictionary](/guides/full-site-delivery/dictionaries/about-dictionaries) to change the percentage of requests logged without having to deploy a new version of your service. The following example uses a dictionary named `service_variables`:

```vcl
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 `false` to construct a log string in custom VCL

To construct a log string in custom VCL, you can use the `false` condition. This condition makes sure nothing is sent to Fastly logging objects.


## Related content

* [Log the data you need for actionable insights](/solutions/examples/custom-logging/)
* [About Conditions](/guides/full-site-delivery/conditions/about-conditions)
