Available in all subroutines.

Emits a log message to Fastly's real time logging system.

log "syslog " req.service_id " logger-name :: client_ip=" client.ip;

The log statement takes just one argument, a message string, but in order for Fastly to route the message correctly, it must be prefixed with "syslog", followed by your service ID and the endpoint name, separated by spaces. The ID of the active service is available as the req.service_id variable, or you can hard code the service ID into the string if you choose to. After this metadata, add a double colon (::) to terminate the header. The rest of the string is sent to the logging endpoint as the log message.

After stripping the header from the message sent from VCL, an endpoint-specific header may be added by the Fastly logging system depending on the requirements of the log endpoint and how you have configured it.

There are no constraints on the format in which you can log. The most straightforward formats to construct in VCL are query strings, due to our native support for the format with functions such as querystring.set. Other common formats like CSV or structured HTTP headers may also be constructed by concatenating portions of strings. Some log endpoints may require more complex formats like JSON or XML; if constructing a string in one of these formats be aware of the need for escaping, and use functions like json.escape and xml_escape.

Log messages must be a single line. Newline characters in log messages will terminate the message.

Logging in Fastly Fiddle

The interactive examples in our developer site and blogs are powered by Fastly Fiddle. To help debug and inspect code when experimenting in Fiddle, we support logging from Fiddle code without any logger prefix:

log "Hello from Fiddle!";

However, this log message would be discarded if sent by a normal service, because it lacks any service ID or destination log endpoint name.

Try it out

log is used in the following solution recipes. Recipes apply VCL to real-world use cases and can be deployed as-is, or adapted for your own service. See the full list of recipesfor more inspiration.

Click RUN on a sample below to provision a Fastly service, execute the code on Fastly, and see how the function behaves.

Comprehensive logging

Fastly offers a myriad of different variables that you can log. See and test a large collection here.

User contributed notes

We welcome comments that add use cases, ideas, tips, and caveats. All comments will be moderated before publication. To post support questions, visit our support center and we'll find you the help you need.