Home » Blog » Apex BOOST: Logger

Apex BOOST: Logger

How much would you love a view of the errors happening in your Salesforce org? Such information is vital for administrators, project managers, and development leads. It allows you to monitor the health of your customizations and find problems before your customers do! Such a view is not possible with standard Salesforce, but is easy to create using the new Apex BOOST Logger!

Logging is Critical

In Salesforce custom development, logging is the only method available for discovering the inner workings of the code at runtime. But most developers only utilize the System.debug method, which writes minimal information to the system debug log. This style of logging can be helpful during development, but the data is short-lived, difficult to access, and cannot be used in workflow (flows, email alerts, reporting, etc).

Apex BOOST is a free library available on the Salesforce AppExchange. Download it today to start monitoring error logs and improve your custom code quality!

Apex BOOST Logger

The Apex BOOST Library has a facility that will greatly enhance logging within your custom code – the Logger class. A log record can be generated easily and with the information that is important to you.

public class MyClass {
  public void myMethod(Account[] accounts) {
    // 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');

    // WARN|scox~ MyClass.myMethod:10 (3) (Account:{Name=GenePoint, ...
    aBoost.Logger.log('(' + accounts.size() + '): ' + accounts);
  }
}

The resulting log records

  • can be viewed on the Logs tab
  • contain rich context information such as Apex class, method, line number, running user, timestamp, and stack trace
  • can generate notifications using flows, email alerts, or scheduled reports
  • are saved in the system, even if an exception rolls back the current transaction (thank you immediate Platform Events!)
  • can be enabled/disabled in setup via Apex BOOST custom settings

Auto Log Creation

An especially acute problem for many customers is getting details on processes that are run independently of user interaction. Again, Apex BOOST makes this simple – log records can be auto-created by all of your batch processes. Implement the Database.RaisesPlatformEvents interface in each Batchable class to auto-generate a log record each time an exception is thrown by the class.

public class MyBatchJob implements
  Database.Batchable<SObject>, Database.RaisesPlatformEvents {
  ...

We continue to innovate and add logging features to Apex BOOST as well. An upcoming release of Apex BOOST will auto-create logs for errors that occur in your flows. No changes to your custom code will be required!

All this means that with little or no impact on your custom development, you’ll be able to start monitoring the errors in your system!

Log Cleanup

Over time, log records will accumulate and may lose relevance. Apex BOOST provides auto-cleanup of old log records. On library install, a job that deletes old log records is scheduled to run each morning. The job can be rescheduled with different parameters by running a snippet of anonymous Apex.

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

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

The age at which a log record will be deleted can be specified in the Apex BOOST custom settings.