Available inall subroutines.
Emits a log message to Fastly's real time logging system.
log "syslog " req.service_id " logger-name :: client_ip=" client.ip;
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
Log messages must be a single line. Newline characters in log messages will terminate the message.
For more information about logging from Fastly services, see our guide to log integrations and best practices.
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 code examples. Examples apply VCL to real-world use cases and can be deployed as they are, or adapted for your own service. See the full list of code examples for more inspiration.
Click RUN on a sample below to provision a Fastly service, execute the code on Fastly, and see how the function behaves.
Fastly offers a myriad of different variables that you can log. See and test a large collection here.