---
title: log
source: https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/log
---

## Syntax [#log-syntax]

```js
newrelic.log(message: string, options?: Object<{ customAttributes?: Object, level?: 'debug|error|info|trace|warn'}>)
```

Captures data as a single log event.

## Requirements [#log-requirements]

-   Browser Pro, or Pro+SPA agent:

    | Agent version       | Configuration behavior                                                                                   |
    | ------------------- | -------------------------------------------------------------------------------------------------------- |
    | `1.261.0 - 1.282.0` | Application settings aren't configurable                                                                 |
    | `1.283.0 - 1.305.0` | Application settings are applied to both console and manual logs                                         |
    | `1.306.0` and above | Console logs and manual logs have separate settings for verbosity, sampling, and enable/disable controls |
-   If you're installing the browser agent via npm and building a custom agent with selected features, you must enable the `logging` feature when creating the `Agent` instance. In the `features` array, add the following:

    ```js
    import { Logging } from '@newrelic/browser-agent/features/logging'

    const options = {
      info: { ... },
      loader_config: { ... },
      init: { ... },
      features: [
        Logging
      ]
    }
    ```

For more information, see the [npm browser installation documentation](https://www.npmjs.com/package/@newrelic/browser-agent#new-relic-browser-agent).

## Description [#log-description]

When you execute this function with a valid message and elective options, the browser agent records the data as a single `log` event.  See the [Logs UI](https://docs.newrelic.com/docs/logs/ui-data/use-logs-ui/) for more information about log events. Any custom attributes supplied to the API call in the `options` argument (`options.customAttributes`) will be appended as top-level attributes on the log event and take precedence over any global custom attributes by [setCustomAttribute](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-agent-spa-api/set-custom-attribute). You can control the `level` of the captured log by supplying a `level` to the `options` argument (`options.level`), which defaults to `info`.

## Parameters [#log-parameters]

| Parameter          | Description                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `message` _string_ | Required. A string value which will be set to the `message` value of the created log event. The `message` property of the log event is the most visible property exposed on the log event and is used across the UI platform when displaying logs.                                                                                                                                                                                      |
| `options` _Object_ | Optional. An object used for supplying optional configurations for the captured log. `options.customAttributes` is an object of key:val pairs that assigns a top-level property and value to the created log for each attribute supplied. The enum `options.level` assigns a log level to the created log event.  The `level` must be one of: `debug | error | info | trace | warn`.  The log level defaults to `info` if not supplied. |

## Examples [#log-examples]

### Capturing a simple log item [#capture-simple-log-item]

```js
newrelic.log('my log message')
// saves a log event with:
// a message of --> 'my log message'
// a level of --> 'info'
```

### Capturing a log item with a specified level [#capture-item-specific-level]

```js
newrelic.log('my log message', {level: 'debug'})
// saves a log event with:
// a message of --> 'my log message'
// a level of --> 'debug'
```

### Capturing a log item with custom attributes [#capture-item-cust-attributes]

```js
newrelic.log('my log message', {customAttributes: {myFavoriteApp: true}})
// saves a log event with:
// a message of --> 'my log message'
// a level of --> 'info'
// an attribute of --> 'myFavoriteApp: true'
```

### Capturing a log item with a specified level and custom attributes [#capture-item-level-cust-attrib]

```js
newrelic.log('my log message', {level: 'debug', customAttributes: {myFavoriteApp: true}})
// saves a log event with:
// a message of --> 'my log message'
// a level of --> 'debug'
// an attribute of --> 'myFavoriteApp: true'
```
