• /
  • EnglishEspañol日本語한국어Português
  • EntrarComeçar agora

log

Syntax

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

Captures data as a single log event.

Requirements

  • Browser Pro, or Pro+SPA agent (v1.261.0 or higher)

  • If you're using npm to install the browser agent and using a non-standard implementation, you must enable the logging feature when instantiating the BrowserAgent class. For example, add the following in thefeatures array:

    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.

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 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. You can control the level of the captured log by supplying a level to the options argument (options.level), which defaults to info.

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

Capturing a simple log item

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

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

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

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'
Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.