---
title: vcl_log
summary: null
url: https://www.fastly.com/documentation/reference/vcl/subroutines/log
---


The built-in `vcl_log` subroutine is executed after the response to the client has finished, and therefore has access to data about the final state of the request, and timing information about the response. Because it is not executed within the critical path of the VCL flow, it is the preferred place to transform and output data to a [log endpoint](/guides/integrations/logging/) using the `log` statement.

> **HINT:** Logs emitted from VCL are routed to your configured endpoint via a [syslog](https://en.wikipedia.org/wiki/Syslog) daemon. To ensure that the log reaches the right endpoint, the message must be prefixed with your service ID and endpoint name. The service ID is available as the VCL variable `req.service_id`, which can be used for convenience. For example:
>
> ```vcl
> log "syslog " + req.service_id + " my-endpoint-name :: ACTUAL LOG TEXT HERE";
> ```

When creating a log endpoint, Fastly will automatically generate a `log` statement for you, which sends a log line to that endpoint for every request. You can disable this behavior by setting the `placement` property of the log endpoint to `"none"` when creating the endpoint.

For more information on creating log endpoints, what to log, and how to format `log` statements, see our [logging integration guide](/guides/integrations/logging/).

## Shielding considerations

If using shielding, i.e. each request normally passes through two Fastly [POPs](/guides/concepts/pop), then the full VCL flow will be executed at both the edge [POP](/guides/concepts/pop) and the shield [POP](/guides/concepts/pop). For requests that do not find a hit in the cache at the edge, this may result in double logging. To avoid logging at the shield, consider wrapping the log statement in a check of `fastly.ff.visits_this_service`:

```vcl
if (fastly.ff.visits_this_service == 0) {
  log "....";
}
```

Alternatively, consider generating a random request ID (for example using `uuid.version4()`) at the edge and including it in the log statement at the edge and the shield, allowing for matching and de-duplication of the data in later analysis.
