Logger

Classin logger@fastly/js-compute 4.0.0View source

Class for connecting to Fastly named log endpoints.

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
In this example we create a logger named `"splunk"` and log the incoming request method
and 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(message: any): void

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

Parameters

message: any

Returns

void