Skip to content

cbsfdevteam/cb_logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 

Repository files navigation

CB_Logger - Custom log framework

Salesforce logging tool powered by Platform Events and Big Objects.
Youtube Video

A log based on Big Objects that is called from apex for a variety of log needs.
“SUCCESS”, “FAIL”, “LOG”, “CALLOUT_RETRY”, “EXCEPTION” and more….
In apex we can use the CB_Logger class and by calling a simple method to determine the log type, subject and body.
The log is initially a platform event which is added to a list of event logs, and we either publish immediately or at the end of the transaction (inside our trigger framework using a single call to the publish method per transaction).
Once the event is published, the event trigger picks it up and one at a time we convert them into big objects.
At this point, we make sure to add a sequence number for each log in the list, because big objects can be considered duplicates and overwrite each other if the index fields are not unique.
The reason for publishing a platform event and not writing directly to the big object is because you cannot mix dml of sObjects with big objects.
By creating a platform event, this starts a new transaction where we can commit the big objects without receiving such dml errors.
Once the objects are committed, we can then go to the CB_Logger UI, and filter by date, log type, or subject.
You can expand the message to view all the details, and if there is something that needs to be shared with a team member you can use the email button in the UI to choose the recipient from a pre-determined list (managed via custom label) and send them a copy.

Install CB_Logger package in your org

Install Package.

Documentation

To log a custom log, use the following method:

CB_Logger.log(LogType,Subject,Body);

To publish saved logs, use the following method:

CB_Logger.publish();

*this method will publish all the logs saved till this point in the running instance.

How to add/change log types:
Go to "LogType" class and add or change the log enum list.

The following log type are prebuilt:

Log type
LOG
SUCCESS
FAIL
ALERT
CALLOUT_FAIL
CALLOUT_SUCCESS

The following log methods are available:
Type method Comments
log log(LogType type, String subject, String Body); Adds a new platform event object to the prepublished list. *You can specify the log type.
log log(String type, String Body); Adds a new platform event object with Type set to "LOG" to the prepublished list.
error - error(String Subject, Object Body);
- error(String Subject, Exception e);
Adds a new platform event object with Type set to "ERROR" to the prepublished list.
alert alert(String Subject, Object Body); Adds a new platform event object with Type set to "ALERT" to the prepublished list.
success success(String Subject, Object Body); Adds a new platform event object with Type set to "SUCCESS" to the prepublished list.
live - live(String Subject, Object Body);
- live(Object Body);
Publish immediately a new Platform Event object with Type set to "LIVE". *for type "LIVE" logs,no Big Object record will be created.
Invocable InvocableLog(List params); An Invocable method that allows you to create logs from flows. In order to use this method, you send in the parameter a List of Strings, each String contains the following:
[Type]~[Subject]~[Message]
The method splits the String for each '~' and builds a Platform Event from the resulted list.
publish publish(); Publish immediately the prepublished list.

How to get to the Logger after installing the package:
Go to the App Drawer -> Choose "CB_Logger".

New Features

Version 1.10:

  • New log for exceptions.
    CB_Logger.error(String Subject, Exception e)
  • New short live log.
    CB_Logger.live(Object Body)
  • New message filter option.
  • Added support for multiple logs, now will join logs with the same subject, minimizing the amount of platform events used on single instance.

Version 1.7 - 1.9:

  • Changed lwc names to include "cb" prefix.
  • New "Time Filter" option when filtering via dates.

Version 1.6:

  • New "Live Mode": a new mode in the logger, accessible via toggle button in UI, that displays platform event logs that arent been saved as big object records. This feature allows you to get logs live, making debugging easier without the standard trace-log process.
  • Invocable method: a new log type allows you to create a log in flows.

Why we made this

We, the Salesforce developers team at Cellebrite, are working very hard to develop solutions, tools and frameworks for our users (internal users and external customers).
As you all know, Salesforce platform has evolved immensely in the past years, and continue to evolve and add new features with each release.
One issue we had issues with and didn’t evolve too much was logging.
Mainly answering these questions:

  • What is happening in my org? Are the main business processes working without issues?
  • Are there any errors?
  • Who was the logged-in user?
  • What record was being created/updated when it happened?
  • Did our scheduled job finish?
  • Did a callout was successful? And many more

Apex logs are useful but you will need to activate a debug log for each user, there is a limit of 24 hours per activation and there is a limit on log file size. Moreover, you will need to be experienced in log reading to get value from it.

Enter our own “CB_Logger”.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published