Apex BOOST Library
v1.7 from Lucidware Solutions (LWS)

Logger

global inherited sharing class Logger
DescriptionThe Logger's primary responsibility is to create Log (aBoost__Log__c) records. It utilizes immediate Platform Events to circumvent rollbacks that happen when an exception is thrown in a transaction. After calling Logger.log, you can be assured that the log record will be committed. In addition to the parameters you pass to a Logger.log method, Apex BOOST will record the context (class, method, line), current user, and stack trace.

In addition to the logging calls you add to your Apex code, logs will be auto-generated (no Apex code changes required) in the following scenarios:

  1. an exception is not caught in a Database.Batchable class that implements Database.RaisesPlatformEvents
  2. a fault is not caught in a screen flow

An additional benefit of Logger is that it can be turned on and off via hierarchical Apex BOOST custom settings. Just adjust the Log Level for any user or profile - even in production - to start creating log records in order to triage problems.

Finally, once you've implemented logging, stakeholders will be able to build reports and workflow to visualize and be notified of errors occurring in the system.

Usage:
 public class MyClass {
   public void myMethod() {
     // ERROR|scox~ MyClass.myMethod:4 simple test
     aBoost.Logger.log('simple test');

     // WARN|scox~ MyClass.myMethod:7 warning test
     aBoost.Logger.log(LoggingLevel.WARN, 'warning test');
   }
 }
 

For more information on logging with Apex BOOST, check out our blog post.

Methods

  log

global static String log()
Description Generate a log entry when the logging level is ERROR. This is useful when the only context required is the class, method, and line number (auto-generated)
Returnsa String including the context, level, and message

  log

global static String log(LoggingLevel level)
DescriptionGenerates a log entry at the specified logging level or less. This is useful when the only context required is the class, method, and line number (auto-generated)
Returnsa String including the context, level, and message
ThrowsInvalidParameterValueException if level is null

  log

global static String log(Object message)
Description Generates a log entry when the logging level is ERROR.
Parametermessage: information (text, exception, etc.) to log
Returnsa String including the context, level, and message

  log

global static String log(LoggingLevel level, Object message)
DescriptionGenerates a log entry at the specified logging level or less.
Parametermessage: information (text, exception, etc.) to log
Returnsa String including the context, level, and message
ThrowsInvalidParameterValueException if level is null

  log

global static String[] log(LogEvent__e[] events)
DescriptionAn invocable logging method ("Log") for use with flows.
Parameterevents: one or more records; these should not be querried from the system, rather, they should be manually constructed in the flow and populated with flow or user values.
Returnsa String for each event; each String includes the context, level, and message
ThrowsInvalidParameterValueException if events are null

Logger.Cleaner

global without sharing class Cleaner extends BatchJob.Handler
DescriptionA batch process that deletes old log records. On initial installation of Apex BOOST, this process is scheduled to run at 1am every day. The Log Days To Keep custom label specifies how many days log records will be kept. The default is DEFAULT_DAYS_TO_KEEP.

Any exceptions thrown by Logger.Cleaner will be logged by Logger.

Usage:
 // schedule the job to run every day at 1am
 System.schedule('Apex BOOST Log Cleaner', '0 0 1 * * ?',
   new aBoost.BatchJob(new aBoost.Logger.Cleaner()));

 // clean old logs immediately
 new aBoost.Logger.Cleaner().run();