Skip to content

LOG_Builder.LogEntry

Class

apex
global class LOG_Builder.LogEntry

Fluent builder for constructing rich log entries with context. Provides a chainable API for setting log level, location, record association, and contextual metadata before emitting the log.

Since: 1.0

Example:

apex
LOG_Builder.build()
    .error(caughtException)
    .at('PaymentService.charge')
    .forRecord(paymentId)
    .withContext('amount', payment.Amount__c)
    .emit();

Methods

MethodDescription
global LOG_Builder.LogEntry at(String classMethod)Sets the originating class and method for the log entry.
global LOG_Builder.LogEntry debug(List<String> messages)Sets the log level to DEBUG with the given batch of messages.
global LOG_Builder.LogEntry debug(String message)Sets the log level to DEBUG with the given message.
global void emit()Emits the log entry with all configured properties.
global void emitAt(String classMethod)Convenience terminal that sets the class/method and emits in one call.
global LOG_Builder.LogEntry error(Exception error)Sets the log level to ERROR with the given exception.
global LOG_Builder.LogEntry error(List<String> messages)Sets the log level to ERROR with the given batch of messages.
global LOG_Builder.LogEntry error(String message)Sets the log level to ERROR with the given message.
global LOG_Builder.LogEntry forRecord(Id recordId)Associates a record ID with the log entry.
global LOG_Builder.LogEntry forRecord(String recordId)Associates a record ID (as String) with the log entry.
global LOG_Builder.LogEntry info(List<String> messages)Sets the log level to INFO with the given batch of messages.
global LOG_Builder.LogEntry info(String message)Sets the log level to INFO with the given message.
global LOG_Builder.LogEntry warn(List<String> messages)Sets the log level to WARN with the given batch of messages.
global LOG_Builder.LogEntry warn(String message)Sets the log level to WARN with the given message.
global LOG_Builder.LogEntry withContext(String key, Object value)Adds a context key-value pair to this log entry.
global LOG_Builder.LogEntry withFingerprint(String key)Sets a grouping fingerprint for this entry, enabling flood control: the first occurrence persists as a full detail row, repeats roll up into daily counter rows.
global LOG_Builder.LogEntry withSummary(String shortMessage)Sets a brief summary message for the log entry.

Method Details

at

apex
global LOG_Builder.LogEntry at(String classMethod)

Sets the originating class and method for the log entry.

Parameters:

  • classMethod (String) - The class and method in format 'ClassName.methodName'

Returns: LOG_Builder.LogEntry - This LogEntry for chaining

Since: 1.0

debug

apex
global LOG_Builder.LogEntry debug(List<String> messages)

Sets the log level to DEBUG with the given batch of messages.

Parameters:

  • messages (List) - The debug messages to log

Returns: LOG_Builder.LogEntry - This LogEntry for chaining

Since: 1.0

debug

apex
global LOG_Builder.LogEntry debug(String message)

Sets the log level to DEBUG with the given message.

Parameters:

  • message (String) - The debug message

Returns: LOG_Builder.LogEntry - This LogEntry for chaining

Since: 1.0

emit

apex
global void emit()

Emits the log entry with all configured properties. Any per-entry context is temporarily set as global context for the duration of the log call, then cleaned up to prevent leaking into subsequent logs.

Since: 1.0

emitAt

apex
global void emitAt(String classMethod)

Convenience terminal that sets the class/method and emits in one call. Equivalent to .at(classMethod).emit().

Parameters:

  • classMethod (String) - The class and method in format 'ClassName.methodName'

Since: 1.0

Example:

apex
LOG_Builder.build().error(caughtException).emitAt('PaymentService.charge');

error

apex
global LOG_Builder.LogEntry error(Exception error)

Sets the log level to ERROR with the given exception.

Parameters:

Returns: LOG_Builder.LogEntry - This LogEntry for chaining

Since: 1.0

error

apex
global LOG_Builder.LogEntry error(List<String> messages)

Sets the log level to ERROR with the given batch of messages.

Parameters:

  • messages (List) - The error messages to log

Returns: LOG_Builder.LogEntry - This LogEntry for chaining

Since: 1.0

error

apex
global LOG_Builder.LogEntry error(String message)

Sets the log level to ERROR with the given message.

Parameters:

  • message (String) - The error message

Returns: LOG_Builder.LogEntry - This LogEntry for chaining

Since: 1.0

forRecord

apex
global LOG_Builder.LogEntry forRecord(Id recordId)

Associates a record ID with the log entry.

Parameters:

  • recordId (Id) - The related record ID

Returns: LOG_Builder.LogEntry - This LogEntry for chaining

Since: 1.0

forRecord

apex
global LOG_Builder.LogEntry forRecord(String recordId)

Associates a record ID (as String) with the log entry.

Parameters:

  • recordId (String) - String representation of the related record ID

Returns: LOG_Builder.LogEntry - This LogEntry for chaining

Since: 1.0

info

apex
global LOG_Builder.LogEntry info(List<String> messages)

Sets the log level to INFO with the given batch of messages.

Parameters:

  • messages (List) - The informational messages to log

Returns: LOG_Builder.LogEntry - This LogEntry for chaining

Since: 1.0

info

apex
global LOG_Builder.LogEntry info(String message)

Sets the log level to INFO with the given message.

Parameters:

  • message (String) - The informational message

Returns: LOG_Builder.LogEntry - This LogEntry for chaining

Since: 1.0

warn

apex
global LOG_Builder.LogEntry warn(List<String> messages)

Sets the log level to WARN with the given batch of messages.

Parameters:

  • messages (List) - The warning messages to log

Returns: LOG_Builder.LogEntry - This LogEntry for chaining

Since: 1.0

warn

apex
global LOG_Builder.LogEntry warn(String message)

Sets the log level to WARN with the given message.

Parameters:

  • message (String) - The warning message

Returns: LOG_Builder.LogEntry - This LogEntry for chaining

Since: 1.0

withContext

apex
global LOG_Builder.LogEntry withContext(String key, Object value)

Adds a context key-value pair to this log entry. Context is scoped to this entry only and does not affect other logs.

Complex types (Maps, Lists, SObjects) are JSON-serialised automatically inside LOG_Engine.setGlobalContext — callers MUST NOT pre-serialise via JSON.serialize(value) or the payload is double-encoded. Pass the value object directly and let the engine decide the wire form. Prefer LOG_Engine.CONTEXT_* constants for key over string literals so cross-framework log entries pivot on the same key namespace.

Parameters:

  • key (String) - The context key (use a LOG_Engine.CONTEXT_* constant where one exists).
  • value (Object) - The context value (any type; auto-serialised when complex).

Returns: LOG_Builder.LogEntry - This LogEntry for chaining

Since: 1.0

withFingerprint

apex
global LOG_Builder.LogEntry withFingerprint(String key)

Sets a grouping fingerprint for this entry, enabling flood control: the first occurrence persists as a full detail row, repeats roll up into daily counter rows. Use a STABLE event-template identity (e.g. 'payment-retry-loop') — never per-occurrence data such as record ids or timestamps, which would make every entry unique and produce MORE rows than plain logging. Keys are trimmed; keys longer than 200 characters or starting with the reserved 'bypass:' prefix are SHA-256 hashed. When a key is hashed, the original key is recorded in this entry's context (LOG_Engine.CONTEXT_FINGERPRINT_SOURCE) so the opaque stored fingerprint stays reconcilable with what you supplied.

Parameters:

  • key (String) - The stable grouping key.

Returns: LOG_Builder.LogEntry - This LogEntry for chaining

Since: 1.1

Example:

apex
LOG_Builder.build().warn('Retry failed').withFingerprint('order-sync-retry').emitAt('OrderSync.run');

withSummary

apex
global LOG_Builder.LogEntry withSummary(String shortMessage)

Sets a brief summary message for the log entry.

Parameters:

  • shortMessage (String) - The summary message

Returns: LOG_Builder.LogEntry - This LogEntry for chaining

Since: 1.0