> For the complete documentation index, see [llms.txt](https://docs.goharrier.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.goharrier.com/technical/best-practices/logging.md).

# Logging

The preferred logging framework for Salesforce development is [Nebula Logger](/technical/frameworks/nebula-logger-logging.md). 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:

| Level                     | Purpose                                                  | Example                                               |
| ------------------------- | -------------------------------------------------------- | ----------------------------------------------------- |
| `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()` or `setRecordId()` when processing specific records.
* `setHttpRequestDetails()` and `setHttpResponseDetails()` for HTTP callouts.
* `setRestRequestDetails()` and `setRestResponseDetails()` for Apex REST web services.
* `addTag()` to include custom tags.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.goharrier.com/technical/best-practices/logging.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
