Logger
Class for connecting to Fastly named log endpoints.
Note: Can only be used when processing requests, not during build-time initialization.
12345678910111213141516171819In this example we create a logger named `"splunk"` and log the incoming request methodand destination.
```js/// <reference types="@fastly/js-compute" />import { Logger } from "fastly:logger";
async function app(event) { let logger = new Logger("splunk"); logger.log(JSON.stringify({ method: event.request.method, url: event.request.url }));
return new Response('OK');}
addEventListener("fetch", event => event.respondWith(app(event)));```Constructor
new Logger(name: string)Creates a new Logger instance for the given named log endpoint.
Parameters
- name: string
The name of the Fastly log endpoint to associate with this Logger instance.
Methods
log
View sourcelog(message: any): voidSend the given message, converted to a string, to this Logger instance's endpoint.
Parameters
- message: any
Returns
void