Apex Aide apexaide

lightning/logger - Add Observability to your custom Lightning Web Components | Salesforce ☁️⚡️

www.salesforcebolt.com· ·Intermediate ·Developer ·2 min read
Summary

Lightning/logger is now generally available for adding observability to custom Lightning Web Components in Lightning Experience. It works by logging component event data through a simple log() method, requiring Event Monitoring and Lightning Logger Events Toggle enabled. Developers can easily integrate it into LWCs to track actions like button clicks for improved monitoring and debugging. This approach helps Salesforce teams gain actionable insights into component usage and behavior without complex setups.

Takeaways
  • Enable Event Monitoring and Lightning Logger Events in Setup before using lightning/logger.
  • Import log() from lightning/logger to log structured messages in LWCs.
  • Use log() to automatically stringify objects for event logging.
  • lightning/logger is available only in Lightning Experience, not Salesforce mobile app.
  • The log() method helps add observability to component events, aiding debugging.

  lightning/logger it's generally available to use now and can be used to add observability to your custom Lightning Web Components. lightning/logger  is available only in Lightning Experience and not in the Salesforce mobile app. To use  lightning/logger , make sure Event Monitoring is enabled in your org and the "Enable Lightning Logger Events" toggle is set to On. lightning/logger  has one method,  log() . log() 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. Turn on Event Monitoring Settings From Setup, in the Quick Find box, enter event, and then select Event Monitoring Settings. Turn on Lightning Logger Events. To add lightning logger in your LWC, you can simply import it from lightning/logger library as shown in the example below.

Lightning Web Components[object Object]