Skip to main content
FCORE_BASE.Logger is the Platform package’s structured logger, available to every package under the FCORE_BASE namespace. It provides structured logging for exceptions, custom messages, and HTTP callouts. Each log persists to the Log__c object. A log is collected in memory and then committed in one of two ways:
  • By DML — written directly to Log__c in the current transaction.
  • By platform event — published as a Log_Event__e platform event, which a subscriber persists. Because the platform event is delivered independently of the current transaction, this option survives a rollback. Use it whenever the surrounding transaction may roll back (for example, when you log an exception and then rethrow it).
Most commit-style methods take a final Boolean shouldCommitByDML argument: pass true to commit by DML, or false to commit by platform event.

Log Levels

The level is the FCORE_BASE.Logger.LogLevel enum:

Always Set the Execution Context First

Call FCORE_BASE.Logger.setApexExecutionContext(Type classType, String methodName) before you log so that the originating class and method are recorded on the log:

Methods

All Logger methods are global static.
The message overload of log requires the fourth action argument — there is no three-argument message overload. The logWithContext correlation variant exists only for an Exception (there is no message or callout overload).

Collect Versus Commit

The plain log(...) overloads only collect a log in memory; nothing is written until you call commitLogs(Boolean shouldCommitByDML). This lets you batch several logs and flush them once. The logAndCommit(...) overloads collect and commit in a single call.

Inner Classes

  • Logger.CalloutLogWrapper wraps an HTTP request/response pair so you can log the request and response bodies and the status. Construct it with CalloutLogWrapper(HttpRequest request, HttpResponse response), then pass it to a callout log or logAndCommit overload.
  • Logger.LogContext is returned by the ...WithContext methods. It carries a uuid String you can hand back to a user or to another system so they can correlate that reference with the stored Log__c record.

Canonical Try/Catch Pattern

When you catch an exception, log it by platform event (so the entry survives the rollback) and then rethrow:

Logging an HTTP Callout