Apex Monitoring Overview

SightLane Apex Monitoring (or Apex Auditing) is a simple way to create runtime visibility in your Apex code. This article describes basic techniques for creating logging with SightLane. The other articles mentioned below cover more advanced techniques.

SightLane logs are not limited to single statements like System.debug() and many logging frameworks.  Instead, SightLane creates monitors that tell complete and persistent stories.  Event logs can be created in very simple situations or across multiple code blocks and even transactional boundaries.  Furthermore, you can keep logs for as long as you like (not just while you're in the Developer Console!)

Step 1: Get an EventLogger

To begin, just ask for a new EventLogger.  This establishes the monitor under which you will log all content for this event.

sightlane.EventLogger el = sightlane.Logging.startLog('My First Monitor');
Pro Tip: Using the SightLane Wrapper package, you can eliminate the need to explicitly reference the SightLane package name in every monitor.  Check out our article on Package Dependency for more.

Step 2:  Log it!

Once you have established your logger, just write down anything that is valuable.  It's the same level of effort as using System.debug, except it's visible to everybody with SightLane access and lasts much longer!

el.log('Something important happened, and I want to share it!');

The SightLane Logging library has dozens of different logging capabilities to help you monitor robustly and easily. For all the details and example code, you can check out our SightLane Logging Reference.

Step 3:  Report the Results

Once the story is complete, call the reportToSightLane method to capture all logged content at once. 

el.reportToSightLane();

Bonus Content

If the monitor you create is relevant to an individual Salesforce record, you can associate the event log directly with that record. Then, you can see the log content and the impacted data records. It's just that simple, saving you a ton of time on issue research!

el.setPrimaryRecordId(theContact.Id);

Bringing it all together

public void updateContact(Contact theContact){
  sightlane.EventLogger el = sightlane.Logging.startLog('My First Monitor');
  el.setPrimaryRecord(theContact.Id);

  <your business code goes here...>
  el.log('Something important happened, and I want to share it!');
  <more business code goes here...>

  el.reportToSightLane();
}
That's it!  Remember that SightLane Monitors are self-registering, so you don't have to do anything else.  Monitor setup and registration are totally optional.  Run this code in your org, then check out the SightLane Control Center page to see what your monitor produced!

 

Frequently Asked Questions

Why is the startLog line so complicated?

Salesforce requires developers to reference the package name before they use any class in a managed package. Check out how to simplify this code with the SightLane Wrapper package

What else can I do besides the log(String) method?

The SightLane Logging library has dozens of methods to help you monitor robustly and easily. For details and example code, check out our SightLane Logging Methods Reference.

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.