---
title: Logger
summary: Class for connecting to Fastly named log endpoints.
url: https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/logger/class.Logger/
---

**Kind:** Class  
**Module:** [logger](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/logger/)  
**Package:** @fastly/js-compute 4.0.1  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/logger.d.ts#L28

Class for connecting to [Fastly named log endpoints](https://developer.fastly.com/learning/integrations/logging/).

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

````javascript
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

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/logger.d.ts#L35

```javascript
new Logger(name: string)
```

Creates a new Logger instance for the given
[named log endpoint](https://developer.fastly.com/learning/integrations/logging).

**Parameters**

- `name`: `string` — The name of the Fastly log endpoint to associate with this Logger instance.

## Methods

### log

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/logger.d.ts#L39

```javascript
log(message: any): void
```

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

**Parameters**

- `message`: `any`

**Returns**

`void`
