Mastering Nebula Logger: Transform Your Salesforce Logging Experience
Introduction:
Are you struggling with the limitations of Salesforce logging? Welcome to Nebula Logger.
Discover how Nebula Logger can revolutionize your approach, providing powerful tools to overcome common logging challenges. In this comprehensive guide, we’ll explore the key features of Nebula Logger and how you can seamlessly integrate it into your Salesforce projects. Unleash the full potential of your logging strategy and seamlessly integrate Nebula Logger for an enhanced and streamlined experience.
Problems with Salesforce Logging:
There are a number of problems with Salesforce Logging.
● One of the most relevant ones is that salesforce permits logging and debug statements only for Apex components. Flows, Lightning Web Components, Process builders and integrations do not have any equivalent options to using System.debug().
● Logs must be enabled for each user and have a time limit. System debug logs are retained for 24 hours and debug logs are retained for 7 days.
● Each debug log must be 20 MB or smaller. If your debug log exceeds this limit they are reduced in size by removing older log lines. Consecutively if you generate more than 1000 MB for debug logs within a 15 minute window, your trace flags are disabled.
● Last but not least, reporting and monitoring of logs are very limited. If you require more detailed reporting and monitoring, you would need to use paid add-ons or third-party tools
How Nebula Logger Can Help:
Nebula Logger is the new, most robust logger for Salesforce.
● Unleash the power of detailed logs across various Salesforce elements, including Apex, Lightning Components, Flow, Process Builder and Integrations.
● Not only does Nebula Logger solve the problems faced by generic logging in Salesforce, it provides enhanced capabilities which makes life a whole lot easier,
● Nebula Logger allows users to seamlessly generate comprehensive logs for their components, facilitating clear debugging and enhanced error understanding within Salesforce.
Nebula Logger as a Solution:
With Nebula Logger, users can enable logging and set various logging levels for different users and profiles, based on their clearance and requirements. Managing logs becomes easier with the customizable dashboards provided, and logs can be tracked by log owner, status/level, priority, etc. Reporting on Log data is also made easier by storing data in custom objects.
Nebula Logger Architecture:
As shown in the above diagram, all of the metadata is broken down into 4 layers:
1. Logger Engine Layer
This layer is the core of Nebula Logger that makes logging work. Currently, Nebula Logger supports Apex, Lightning web components & aura components, Flows, including a generic Flow log entry, a record-specific Flow log entry, and a collection-specific Flow log entry
2. Log Management Layer
This layer provides the ability to view and manage logging data, using the Logger Console lightning app. The Logger Console Lightning app, provides a customizable dashboard, along with tables and different pages to view individual logs, with fields for tracking and managing the logs. This layer includes 4 custom objects. Log__c and LogEntry__c which enable users to manage & report on logging data, and LogEntryTag__c and LoggerTag__c which stores your tags
3. Configuration Layer
Admins, developers, and architects can control & customize Nebula Logger’s built-in features, using custom settings, custom metadata types, and permission sets. This layer includes:
Custom Hierarchy Settings:
● LoggerSettings__c for user-specific configurations
Custom Metadata Types:
● LoggerParameter__mdt for system-wide key-value pair configurations.
● LogEntryDataMaskRule__mdt for configuring regex-based data masking rules
● LogStatus__mdt for configuring which picklist values in Log__c.Status__c map to IsClosed__c and IsResolved__c
● LogEntryTagRule__mdt for configuring tagging rules
Permission Sets
● LoggerAdmin
● LoggerLogViewer
● LoggerEndUser
● LoggerLogCreator
4. Plugin Layer
This layer enables users to add new functionality to Nebula Logger by creating, adding or installing plugins.Currently, a plugin is available for Slack, and other plugins are in development. Plugins can be built for any of the 5 included objects.
How to Install Nebula Logger:
https://github.com/jongpie/NebulaLogger
The above link provides a link to install Nebula Logger directly into your sandbox or development org. Once you click on the button, it will ask you to enter your Salesforce account ID and password to login. After successfully logging in, select “For Admins” and install the package into your Salesforce org. There are 3 available options for installing Nebula Logger onto your Salesforce org.
Install the unlocked package: This is the recommended approach, as it makes upgrading (and uninstalling) much easier, and it provides features that are not available in the managed package.
Install the managed package: This has the same metadata as the unlocked package, but due to some platform limitations with how managed packages work, several features are not available in the managed package edition.
Deploy the metadata directly to your org: This is similar to the unlocked packages, minus some capabilities of upgrading or installing.
It is recommended to install the unlocked package in your sandbox.
After installing Nebula Logger in your org, there are a few configuration changes needed. Go to settings and advance user details. Click Assign permission set(s) to users and add the following permission sets:
● LoggerAdmin provides view-all and modify-all access to all log records.
● LoggerLogCreator provides the minimum access needed for users to generate logs via Apex, Lightning Components, Flow or Process Builder
● LoggerEndUser provides access to generate logs, as well as read-only access to any log records shared with the user.
● LoggerLogViewer provides view-all access (read-only) to all log records. This does not provide access to generate logs.
Code Examples:
Logger for Apex
For Apex, Nebula Logger provides a Logger class which has many methods that can be used to add different levels of logging Each logging level method has different overloads to support different parameters.
// This will generate a debug statement within developer console
System.debug(‘Debug statement using native Apex’);
This will create a new `Log__c` record with multiple related `LogEntry__c` records
Logger.error(‘log entry with logging level == ERROR’);
Logger.warn(‘log entry with logging level == WARN’);
Logger.info(‘log entry with logging level == INFO’);
Logger.debug(‘log entry with logging level == DEBUG’);
Logger.fine(‘log entry with logging level == FINE’);
Logger.finer(‘log entry with logging level == FINER’);
Logger.finest(‘log entry with logging level == FINEST’);
Logger.saveLog();
Sample Code for “Apex Trigger”:
Here I have written an Apex trigger to automatically trigger a contact creation when an account is created. I have intentionally left out the Last Name field which is a required field. The Logger.error() method generates the log message and the Logger.saveLog() method will save the log.
trigger InsertContact on Account (after insert) {
List<Contact> conList = new List<Contact>();
for(Account acc : Trigger.new)
{
conList.add(new Contact(FirstName=’John’, AccountId=acc.id));
}
try {
insert conList;
System.debug(‘Contact List’+conList);
} catch(DmlException e) {
Logger.error(e.getMessage());
Logger.saveLog();
}
}
Logger for Flows:
For Flows, Nebula Logger provides several logging actions each with different functionalities.
● ‘Add Log Entry’ – uses the class FlowLogEntry to add a log entry with a specified message
● ‘Add Log Entry for an SObject Record’ – uses the class FlowRecordLogEntry to add a log entry with a specified message for a particular SObject record
● ‘Add Log Entry for an SObject Record Collection’ – uses the class FlowCollectionLogEntry to add a log entry with a specified message for an SObject record collection
● ‘Save Log’ – uses the class Logger to save any pending logs.
Once you have created your flow, add the Add Log Entry action to generate the log, followed by the Save Log action to save the log. Once the flow is triggered, the log will generate and be saved in the dashboard.
Logger for Lightning Web Component
In order to use Nebula Logger in your Lightning Components , it has to be added to your lwc’s markup:
Sample code example or Logging from “Lightning Web Components”:
<template>
<c-logger></c-logger>
<div>Nebule Logger Component</div>
</template>
Once you’ve added the logger component to your markup, you can call it in your LWC controller. Nebula Logger provides similar functionalities for LWC just like in Apex:
import { LightningElement } from ‘lwc’;
export default class Logger extends LightningElement {
log() {
const logger = this.template.querySelector(‘c-logger’);
logger.error(‘ERROR!!!’).addTag(‘TAG’);
logger.warn(‘WARN!!!’);
logger.info(‘INFO!!!’);
logger.debug(‘DEBUG!!!’);
logger.fine(‘FINE!!!’);
logger.finer(‘FINER!!!’);
logger.finest(‘FINEST!!!’);
logger.saveLog();
}
}
It is important to remember to add the logger.saveLog() at the end.
Logger for Aura:
Similar to how it is demonstrated above, to use Nebula Logger in aura, it has to be added to your aura component’s markup:
Sample code example for Logging from “Aura”:
<aura:component implements=”force:appHostable”>
<c:logger aura:id=”logger” />
<div>My component</div>
</aura:component>
Once you’ve added logger to your markup, you can call it in your aura component’s controller:
({
logSomeStuff: function (component, event, helper) {
const logger = component.find(‘LOGGER’);
logger.error(‘ERROR!!!’).addTag(‘TAG’);
logger.warn(‘WARN!!!’);
logger.info(‘INFO!!!’);
logger.debug(‘DEBUG!!!’);
logger.fine(‘FINE!!!’);
logger.finer(‘FINER!!!’);
logger.finest(‘FINEST!!!’);
logger.saveLog();
}
});
Logger for API
Using Nebula Logger in an API, works the same way as mentioned above in Apex. You can use the same methods to generate and save the log. You need to add a try-catch-finally block, in the apex class.
Sample code example for Logging from “API”:
public class PhoneVerificationAPI {
public static PhoneResponse InvokeVeriphoneApi(string mobileNum){
string apiKey = ‘#################################’;
string veriphoneEndpoint = ‘https://api.veriphone.io/v2/verify?phone=’+mobileNum+’&key’+apiKey;
//Http
Http http = new Http();
//HttpRequest
HttpRequest request = new HttpRequest();
request.setEndpoint(veriphoneEndpoint);
request.setMethod(‘GET’);
request.setTimeout(60000);
//HttpResponse
HttpResponse res = http.send(request);
//Response instance to return to calling class
try {
//HttpResponse res = http.send(request);
Logger.debug(‘Debug:’ + res.getStatusCode());
Logger.info(‘Logging API response’);
Logger.info(‘Http Status Code: ‘ + res.getStatusCode());
Logger.warn(‘Http Status Message: ‘ +res.getBody());
} catch(Exception e) {
Logger.error(‘API Callout Error’, e);
} finally {
Logger.saveLog();
}
PhoneResponse pres = (PhoneResponse) JSON.deserialize(res.getBody(), PhoneResponse.class);
return pres;
}
public class PhoneResponse{
public string status;
public string phone;
public boolean phone_valid;
public string phone_type;
public string phone_region;
public string country;
public string country_code;
public string country_prefix;
public string international_number;
public string local_number;
public string e164;
public string carrier;
}
}
In the developer console, click debug and click ‘Open Execute Anonymous Window’.
PhoneVerificationAPI.PhoneResponse p = PhoneVerificationAPI.InvokeVeriphoneApi(‘+917399457294’);
system.debug(‘Response is’+p);
Write the above code. Select ‘open log’ and click ‘execute’ The info, warning and errors will get logged in the Nebula Logger Dashboard.
Log Monitoring and Management:
Nebula Logger’s dashboard is a control center for your logs. It provides a clear overview of log activities and allows for easy management. You can edit the tables available, create custom dashboards, view details of individual logs, track logs from various fields and a ton of other stuff easily and efficiently.
Nebula Logger Home Page
Log Entry Daily Summary
Log Entry Origin Summary
Log Entry Daily Retention Summary
Nebula Logger Logs Page
Log Details
Log Entry Details
Log Entry Warnings
Conclusion:
Nebula Logger offers a robust and user-friendly solution to the common challenges of Salesforce logging. By choosing Nebula Logger, you ensure that your logging process is efficient, thorough, and tailored to your project’s needs. Try it out today and experience a significant improvement in your logging practices.