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 theBrowserAgent
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 |
---|---|
string | Required. A string value which will be set to the |
Object | Optional. An object used for supplying optional configurations for the captured log. |
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'