Skip to main content
Version: 2.5.0

Logger()

The Logger constructor lets you connect your Fastly Compute application to a Fastly Named Logger.

Note: Can only be used when processing requests, not during build-time initialization.

Syntax

new Logger(name)

Note: Logger() can only be constructed with new. Attempting to call it without new throws a TypeError.

Parameters

  • name : string
    • The Fastly Logger which should be associated with this Logger instance

Return value

A new Logger object.

Examples

In this example we have a create a logger named "splunk" and logs the incoming request method and destination.

/// <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)));