Logger
lightning-logger
Logs a string as the message. The module also validates and stringifies other types. It truncates messages over a certain length and logs a blank string for an empty input. Messages are tokenized and can't be seen outside of the customer's org.
For Use In
Lightning Experience
The lightning/logger module provides a function to add observability to your Lightning web components using the Custom Component Instrumentation API. Use the log() function to log custom messages to Event Monitoring from your components. In your component's Javascript file, import the function from the lightning/logger module.
lightning/logger is available only in Lightning Experience and not in the Salesforce mobile app. Event Monitoring must be enabled in your org to use lightning/logger.
The browser sends event logs for lightning/logger to the server in batches when the user interacts with the page and when the page closes or refreshes. If the user's connection is interrupted or the login session ends due to inactivity, any pending event logs for lightning/logger on the browser are deleted. There isn’t a way to retrieve these logs.
Logs the event data from the component.
| Parameter | Type | Description |
|---|---|---|
| message | string or object | The message to be logged to the Lightning Logger Event Type in Event Monitoring. The maximum string length is 4096 characters. The log() function automatically stringifies an object passed in. |
The following example logs a click from within a button component. The log() function can be used for any event.
Create the HTML template for your component.
In the JavaScript, import log from lightning/logger and use it in the handleClick function. In this example, clicking on the button creates an object that is passed to Event Monitoring.
Object Reference for the Salesforce Platform: Lightning Logger Event Type