Logger()
The Logger
constructor lets you connect your Fastly Compute application to a Fastly Named Logger.
Syntax
new Logger(name)
Note:
Logger()
can only be constructed withnew
. Attempting to call it withoutnew
throws aTypeError
.
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";
const logger = new Logger("splunk");
async function app (event) {
logger.log(JSON.stringify({
method: event.request.method,
url: event.request.url
}));
return new Response('OK');
}
addEventListener("fetch", event => event.respondWith(app(event)));