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

# 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

```js
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`](../Logger.mdx) object.

If the `this` value does not inherit from `Logger.prototype`, a [`TypeError`](../../../globals/TypeError/TypeError.mdx) is thrown.

## 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.prototype.log 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";
let 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)));
`
  },
  "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";
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)));
```

</Fiddle>