> For the complete documentation index, see [llms.txt](https://triton.pharos.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://triton.pharos.ai/common-apex-usage-patters/log-levels.md).

# Log Levels

Choosing the right log level in Apex — the severity scale, the shorthand methods, and tuning verbosity per environment with metadata instead of code changes.

A level answers one question: how important is this log? In Apex you use levels for two things — telling a human how urgent a record is, and letting Triton decide *at runtime* whether the log is even worth saving. That second part means you can run chatty in a sandbox and quiet in production **without changing a line of code**.

The mechanics of runtime filtering (the `Log_Level__mdt` metadata, specificity resolution, the defaults) live in [Core Concepts → Log Levels](https://triton.pharos.ai/core-concepts/log-levels.md). This page is about *using* levels well in Apex.

## The scale

Seven levels, least to most verbose:

| Level                       | Reach for it when…                                                                         |
| --------------------------- | ------------------------------------------------------------------------------------------ |
| `ERROR`                     | Something failed and a human should look — exceptions, failed callouts, broken invariants. |
| `WARNING`                   | Something recoverable or suspicious — retries, partial DML failures, approaching a limit.  |
| `INFO`                      | A notable business event — "order placed", "sync completed". Your production signal.       |
| `DEBUG`                     | Developer detail useful while diagnosing.                                                  |
| `FINE` / `FINER` / `FINEST` | Increasingly chatty tracing — payload dumps, loop-level detail, everything.                |

## Setting the level

Two equivalent ways — an explicit `.level(...)`, or the shorthand method on `Triton`:

{% code lineNumbers="true" %}

```apex
Triton.log(Triton.t.summary('Order placed').level(TritonTypes.Level.INFO));
Triton.info(Triton.t.summary('Order placed'));   // identical
```

{% endcode %}

The shorthands — `Triton.error/warning/info/debug/fine/finer/finest(builder)` — set the level and buffer in one call. (`Triton.error(...)` also flags the log for issue creation.) There's no `errorNow`; for immediate publishing at a level, set it on the builder and call `logNow`:

{% code lineNumbers="true" %}

```apex
Triton.logNow(Triton.t.summary('Payment capture failed').error().exception(e));
```

{% endcode %}

## Worked examples

Same code, different levels — pick the one that matches the *audience* for the message.

{% code lineNumbers="true" %}

```apex
// ERROR — something broke
try {
    processAccount(account);
} catch (Exception e) {
    Triton.error(Triton.t.area(TritonTypes.Area.Accounts).exception(e));
}

// WARNING — approaching a governor limit
if (System.Limits.getQueries() > System.Limits.getLimitQueries() * 0.8) {
    Triton.warning(Triton.t
        .area(TritonTypes.Area.Accounts)
        .summary('Approaching SOQL query limit')
        .details('Used ' + System.Limits.getQueries() + ' of ' + System.Limits.getLimitQueries()));
}

// INFO — a business milestone
Triton.info(Triton.t
    .area(TritonTypes.Area.Accounts)
    .summary('Account created')
    .details('Account ' + newAccount.Id + ', owner ' + newAccount.OwnerId));

// DEBUG — diagnostic detail
Triton.debug(Triton.t
    .area(TritonTypes.Area.Accounts)
    .summary('Validating account')
    .details('Industry: ' + account.Industry));

// FINE — loop-level tracing
Triton.fine(Triton.t
    .area(TritonTypes.Area.Accounts)
    .summary('Processing record ' + (i + 1) + ' of ' + accounts.size())
    .details('Account ' + account.Id));
```

{% endcode %}

## Tune verbosity per environment

The point of levels is that **the same code behaves differently by environment** — because a `Log_Level__mdt` record, not your Apex, decides what persists. Write the log once at the right level:

{% code lineNumbers="true" %}

```apex
Triton.debug(Triton.t
    .area(TritonTypes.Area.Accounts)
    .summary('Account validation started')
    .details('Validating: ' + accountData));
```

{% endcode %}

With a metadata rule of `Category: Apex → INFO` in production, that `DEBUG` log is dropped; bump the same rule to `DEBUG` (or `FINEST`) in a sandbox and it flows. No redeploy of Apex.

## Choosing levels well

* **Reserve `ERROR` for things a human should act on.** If everything is an error, nothing is.
* **Make `INFO` your production signal.** Ask "would I want to see this in prod?" — if yes, it's `INFO` or higher.
* **Push volume down the scale.** Loop bodies, payload dumps, and step-by-step traces belong at `FINE` and below, where filtering switches them off cheaply.
* **Don't gate logs with `if` statements.** Resist `if (debugMode) Triton.debug(...)`. Log at the right level and let the metadata decide — that's the whole point.

{% hint style="warning" %}
**Watch expensive details.** Filtering happens *after* the builder is constructed, so heavy `JSON.serialize(...)` or string concatenation in `.details(...)` still runs even when the log is dropped. For very hot paths, guard the expensive construction, not the log call.
{% endhint %}

For deeper guidance on designing a level strategy across a codebase, see [Log Levels: When to Use What](https://triton.pharos.ai/triton-best-practices/log-levels-and-usage.md).
