> 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/triton-best-practices/core-principles.md). Agents can also search and read this documentation through its [MCP server](https://triton.pharos.ai/~gitbook/mcp).

# Core Principles

The handful of ideas that make Triton logging worth having — and a master Do/Don't list you can hand to a new team member on day one.

Good logging isn't about logging *more*. An org drowning in undifferentiated `System.debug` output is worse off than one with a few well-placed, well-labeled logs, because volume without structure is just noise you pay to store. Everything in this section comes back to a small set of principles. Learn these and the specific patterns on the following pages will feel obvious.

## Consistency beats cleverness

The single most valuable property of a log is that it looks like every other log of its kind. If one developer writes `.area(TritonTypes.Area.Accounts)` and another writes `.area('Account')` and a third writes `.area('acct')`, no filter, dashboard, or alert will ever line them up — and the whole point of structured logging evaporates.

This is why the [template pattern](https://triton.pharos.ai/triton-best-practices/templates-and-builder-pattern.md) exists and why we lean on it so hard: set the shared fields once, log from `Triton.t`, and every log in that unit of work is automatically consistent.

{% code lineNumbers="true" %}

```apex
// Set the shape of your logs once, at the top of the unit of work
Triton.setTemplate(Triton.makeBuilder()
    .category(TritonTypes.Category.Apex)
    .area(TritonTypes.Area.OpportunityManagement));

// Every log from here shares category + area, for free
Triton.info(Triton.t.summary('Sync started'));
Triton.error(Triton.t.summary('Sync failed').exception(e));
```

{% endcode %}

## A log is only as good as its context

A log that says `"Update failed"` is almost useless. A log that says `"Update failed"`, is tied to the three records involved, carries the transaction id, and captures the stack trace and governor limits, is something you can actually debug from.

The good news: Triton does most of the heavy lifting automatically. When you call `Triton.log(...)`, the framework captures the stack trace, derives the operation (class/method), records governor-limit usage, and — for Apex logs — stamps the execution context (trigger operation, batch size, async type). Your job is to add the business context only Triton can't infer: which records this is about (`.relatedObject(s)`), and a human-readable `.summary()`. See [Context & Related Objects](https://triton.pharos.ai/triton-best-practices/context-and-related-objects.md).

## Right level, right volume

Every log gets a [level](https://triton.pharos.ai/triton-best-practices/log-levels-and-usage.md), and the level does double duty: it tells a human how urgent the record is, and it lets you tune volume per environment through `Log_Level__mdt` — no code change. Reserve `ERROR` for things a person should actually look at, make `INFO` your production signal, and push loop-level chatter down to `FINE` and below where filtering can switch it off cheaply.

The anti-pattern to avoid: gating logs behind your own flags (`if (debugMode) Triton.debug(...)`). Log at the honest level and let metadata decide what persists. That's the whole point of the level system.

## Correlate across boundaries

Modern Salesforce work rarely stays in one place. A button click runs an LWC, calls Apex, commits a DML that fires a Flow, which enqueues a Queueable. If each of those logs in isolation, you get five disconnected stories. Start a [transaction](https://triton.pharos.ai/triton-best-practices/transaction-management.md) at the entry point and carry the id across the hops, and you get one trace you can read top to bottom.

## Safe by default

Logs are durable and widely readable, so treat them like it. Never log secrets, tokens, passwords, or regulated PII. Do log the things that make debugging possible without exposing anything sensitive: record ids, correlation ids, counts, durations, and status codes. When you attach an integration payload, sanitize it first.

## The master Do / Don't list

Hand this to anyone new to Triton. It's the whole section compressed to one screen.

{% hint style="success" %}
**Do**

* **Set a template** per unit of work and log from `Triton.t`.
* **Use `.exception(e)`** for errors — it sets the level, type, summary, stack trace, and issue flag in one call.
* **Buffer routine logs**, and publish critical ones immediately with `Triton.logNow(...)`.
* **Flush at boundaries** — end of a trigger handler, batch `execute`, or in a `finally` block.
* **Attach related records** with `.relatedObject(s)` so logs correlate to data.
* **Start/resume/stop transactions** across LWC → Apex → Flow.
* **Use stable values** for Category/Type/Area — the built-in enums where they fit, and your own `String` constants for org-specific Types and Areas, never edits to the shipped enums.
  {% endhint %}

{% hint style="danger" %}
**Don't**

* **Don't use `System.debug`** in application code — it vanishes with the debug log.
* **Don't reach for `Triton.instance`** — that's the 1.x singleton; 2.0 is fully static.
* **Don't log PII or secrets**, and don't dump raw payloads without sanitizing.
* **Don't gate logs** behind `if (debug)` flags — set the level and let `Log_Level__mdt` filter.
* **Don't over-log tight loops** at `INFO` — that's what `FINE`/`FINER`/`FINEST` are for.
* **Don't swallow exceptions** after logging unless the design genuinely calls for recovery.
* **Don't invent ad-hoc classification strings** — extend the taxonomy instead.
  {% endhint %}

## Where to go next

These principles are the "why." The rest of the section is the "how":

* Put them into practice with [Templates & the Builder Pattern](https://triton.pharos.ai/triton-best-practices/templates-and-builder-pattern.md).
* See them applied to real contexts in [Implementation Patterns](https://triton.pharos.ai/triton-best-practices/implementation-patterns.md).
* Keep them alive on a growing team with [Standards Enforcement](https://triton.pharos.ai/triton-best-practices/standards-enforcement.md).
