Salesforce Developer Deep Dive: Lightning Logger

If you’re a Salesforce developer, implementing a logging strategy can be an important part of your workflow, allowing you to do everything from track key events in your custom workflows to troubleshooting recurring problems. And if you’re a Salesforce end user, you absolutely should be asking about and understanding your developer’s logging strategy.

In this video, TruSummit Solutions’ Salesforce Senior Developer Mike Chandler explores Salesforce’s Lightning Logger feature, new as of Salesforce’s Spring 2024 release. Through a live demo, he augments an existing implementation with Lightning Logger and evaluates the steps needed to surface and read the log entries created.


Hi, I’m Mike, a Salesforce developer with TruSummit Solutions. In this video, I’ll be talking about the new lightning logger module for Lightning web components and whether or not it’s suitable for your logging requirements. Implementing some sort of logging strategy can be an important part of your work as a developer for a variety of reasons. From tracking key events in your custom workflows to troubleshooting recurring problems. If you’re a Salesforce customer, asking your developer about their logging strategy is a reasonable question to ask. And if you’re a Salesforce developer, answering that question is easier now thanks to this feature, which is new as of Spring 24. Let’s augment an existing implementation with Lightning Logger and see what we need to do to surface and read the log entries that we create. And this is going to help us understand if Lightning Logger’s capabilities are really everything that we need.

We’re looking at an opportunity record right here in a scratch org. I’ve got an unfinished custom workflow in this org developed, customized, unique quote building process. It’s a multi-step process, and our customers asked us that we log every single instance of a customer advancing from one step to the next. So let me just go ahead and briefly step you through this workflow. We’re looking at a very simple opportunity record. I’ve got this custom component here with a button that says Create quote, and when I click on that, it’s going to fire up this multi-step process, and this is what we want to track. So I’m going to click on the test type here, and I’m going to click this continue button. So that’s the item that we want to log. Anytime somebody clicks this continue button, I want to track that. So I’ve just moved on to the next step, completed this form, and again, I’ll select continue. And this again is the event that I want to track. So that gives you an idea of what it is that we’re going for. So I’ve moved over to our code and I’m going to just take you through this implementation. It is surprisingly simple. The first thing that we want to do is create our import. So let me do that. We’re going to import the log function, and this is going to come directly from Lightning Logger.

And with that done, I’m just going to scroll down and see if I can find that function that handles my continue button. And this is it. And I am just going to put my message here, very simple. I just invoke this log method and I pass it a string as an argument.

And there you have it. I’ll go ahead and save this, deploy it. And we’ll just go ahead and run through that workflow one more time. And back in the browser, we’ll do that create quote button. And I’ll just do this one time just to make sure that we capture this continue event. And that’s it. Let’s go ahead then and see what we can do to grab these logs. But first, let’s talk about some of the things that are important to notice. Okay, we’re on the documentation for event monitoring. The first and probably the most important thing to mention, which is actually clearly called out in the documentation here, is that event monitoring IS an additional service. You’ll want to make sure that your org supports event monitoring before you commit to using Lightning Logger. Secondly, to access event logs, the view event log files and the API enabled permissions are required. So if you can’t see those logs, make sure that you check your permission. And then lastly, out of the box mechanisms for actually viewing your event logs inside Salesforce are few and brand new. In fact, still in beta. Most of the documentation is going to point you to a Heroku hosted app. But there is an event logger browser that you can try now in beta. And then one big surprise that you may encounter is that your event logs may not be available right away, and they can sometimes take hours to appear, which is definitely happening to me right now. So let’s go ahead and take a look at that. I’m going to just take us into setup. I’ll do a quick search for event log. I see the event log file browser, so I’m going to select that. And now the magic of editing is going to make my logs appear right away.

They actually were not here initially. I’ve had to wait several hours for them to appear. But let’s go ahead and filter this by the Lightning Logger type and apply. So this is going to bring up my logs. Let me just show you the first one. It’s going to let me download it as a CSV file. That’s not the most friendly thing in the world, but it’s going to give us a raw look at the log itself. Let’s look at that. This is the CSV file open in Excel. I’m just going to log over or just scroll over here to the message and just show you right here that we did capture that. I heard the continue button log message that we got in our source code. As you can see right here, using Lightning Logger to track and log interesting and meaningful events is pretty darn easy, and it doesn’t require you to depend on a third party or implement something from scratch, which is nice.

Just keep in mind that event logs are delayed in appearing in your org’s event log browser. So if urgent troubleshooting is your goal, this may not be ideal, but as long as it’s a long-term solution for critical event monitoring, you can’t go wrong. The event log browser that’s in beta in your setup is okay. It gives you access to the file. You can download it and look at it in its raw format, which isn’t really that great. So if your admins are looking for something that’s a little bit more user-friendly, you may actually find that you might be better off implementing something custom. On the other hand, if your IT organization actually downloads these event logs for you and is aggregating them all together in a system like Splunk, then this might work. This might be okay. There’s certainly plenty to consider before choosing Lightning Logger as your logging solution of choice. So keep all of these points in mind. That’s going to conclude this video and I’ll see you in the next one.

Need help leveraging the latest Salesforce features and functionalities? Our developers are here for you! You know where to find TruSummit Solutions.  

Featured Articles

Ready to Get the Conversation Started?

We're happy to learn more about you, your business, and how we can help. No pressure, no pitches, just perspective.