Logging
The preferred logging framework for Salesforce development is Nebula Logger. It provides a structured and consistent way to handle logging across both Apex and Lightning Web Components (LWC).
Avoid using System.debug() in Apex or console.log() in LWC for production-level logging. These methods lack persistence, structured formatting, and centralized management capabilities essential for enterprise applications.
How to Compose Good Log Messages
An effective log message should answer: Who, What, When, Where, Why, and How (when relevant).
Logging Taxonomy
A well-defined logging taxonomy ensures consistency across your Salesforce org and enables effective observability. Structure your logs using these core dimensions:
Severity Levels
Map business and technical events to appropriate severity levels:
ERROR
Unrecoverable failures, exceptions, integration failures
Logger.error('Payment failed', e, paymentRecordId);
WARN
Recoverable issues, deprecated usage, near-misses
Logger.warn('Fallback API used due to timeout');
INFO
Significant business events, milestones
Logger.info('Order confirmed', order.Id);
DEBUG
Detailed diagnostic data (disable in prod via settings)
Logger.debug('Processing 50 records', records);
FINE, FINER, FINEST
Verbose tracing (use sparingly)
Logger.finer('Loop iteration: ' + i);
On production, set logging to WARN or ERROR to minimize noise. Use DEBUG or lower levels in development or troubleshooting scenarios.
Log Categories
Organize logs by functional area to enable targeted filtering:
Contextual Metadata
Enrich logs with structured metadata for correlation and analysis. Use the following methods from the LogEntryBuilder class to add context:
setRecord()orsetRecordId()when processing specific records.setHttpRequestDetails()andsetHttpResponseDetails()for HTTP callouts.setRestRequestDetails()andsetRestResponseDetails()for Apex REST web services.addTag()to include custom tags.
Last updated
Was this helpful?