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.
instrumentationAPI.html
<template>
<lightning-card title="lightning/logger" icon-name="utility:user">
<lightning-button label="Click Me" onclick={handleClick}></lightning-button>
</lightning-card>
</template>
instrumentationAPI.js
import { LightningElement } from 'lwc';
import { log } from 'lightning/logger'
export default class InstrumentationAPI extends LightningElement {
handleClick() {
let msg = {
type: "Click",
action:"Approve"
}
log(msg);
console.log(JSON.stringify(msg));
}
}
Output
0 Comments