Skip to main content
Version: 3.27.2

Logger.prototype.log

log(): string

Sends the given message, converted to a string, to this Logger instance's endpoint.

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

Syntax

log(message)

Return value

undefined.

Description

Send the given message, converted to a string, to this Logger instance's endpoint.

The log() method requires its this value to be a Logger object.

If the this value does not inherit from Logger.prototype, a TypeError is thrown.

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