---
hide_title: false
hide_table_of_contents: false
pagination_next: null
pagination_prev: null
---

# `Logger()`

The **`Logger` constructor** lets you connect your Fastly Compute application to a [Fastly Named Logger](https://developer.fastly.com/learning/integrations/logging/).

## Syntax

```js
new Logger(name)
```

> **Note:** `Logger()` can only be constructed with `new`. Attempting to call it without `new` throws a [`TypeError`](../../globals/TypeError/TypeError.mdx).

### 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.

<Fiddle config={{
  "type": "javascript",
  "title": "Logger Example",
  "origins": [
    "https://http-me.fastly.dev"
  ],
  "src": {
    "deps": "{\n  \"@fastly/js-compute\": \"^3\"\n}",
    "main": `
/// <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)));
`
  },
  "requests": [
    {
      "enableCluster": true,
      "enableShield": false,
      "enableWAF": false,
      "method": "GET",
      "path": "/status=200",
      "useFreshCache": false,
      "followRedirects": false,
      "tests": "",
      "delay": 0
    }
  ],
  "srcVersion": 1
}}>

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

</Fiddle>