> 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/instrumentation-skills/audit-logging.md).

# Audit Logging Coverage

The audit-logging skill scans a Salesforce project read-only, reports where Triton logging is missing or wrong, and produces a prioritized rollout plan.

The **audit-logging** skill answers the question you have before any rollout: *how bad is it, and where do I start?* It reads a project **without writing anything** and produces two things — a **coverage report** (what's instrumented, what isn't, and what's wrong) and a **prioritized plan** you can hand straight to [`instrument-org`](https://triton.pharos.ai/instrumentation-skills/instrument-org.md).

It's the read-only sibling of the instrumentation skills. Nothing it finds is changed; it only tells you what it found.

{% hint style="info" %}
**Invocation is agent-specific.** In agents that support slash commands (Claude Code, Cursor) you invoke it as `/pharos:audit-logging <path>`; in others you point the agent at this skill and a directory. See [Running these in your agent](https://triton.pharos.ai/instrumentation-skills.md#running-these-in-your-agent).
{% endhint %}

## Usage

{% code lineNumbers="true" %}

```bash
/pharos:audit-logging [<path>] [--format md|json] [--fail-on error,debug] [--tech apex,lwc,flow]
```

{% endcode %}

| Argument    | Required | Meaning                                                                        |
| ----------- | :------: | ------------------------------------------------------------------------------ |
| `<path>`    |          | Project root or subtree. Defaults to the detected project root.                |
| `--format`  |          | `md` (default, human-readable) or `json` (machine-readable, for CI).           |
| `--fail-on` |          | Exit non-zero when a given class of finding is present — for use as a CI gate. |
| `--tech`    |          | Restrict to some technologies. Defaults to all three.                          |

## What it checks

The checks mirror the [Standards Enforcement](https://triton.pharos.ai/triton-best-practices/standards-enforcement.md) review checklist, sorted into hard failures (a machine can be certain) and judgment calls (flagged for a human).

### Hard findings — unambiguous

| Finding                                 | Why it matters                                                                                                                                                     |
| --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **`System.debug` in application code**  | Invisible telemetry — should be a `Triton.debug(...)`.                                                                                                             |
| **`Triton.instance` usage**             | The removed 1.x singleton; its presence means un-migrated code. Route it to [`migrate-to-2.0`](https://triton.pharos.ai/instrumentation-skills/migrate-to-2.0.md). |
| **Catch-but-not-logged**                | A `catch` block with no Triton call — the most common way errors go dark.                                                                                          |
| **Missing flush at a boundary**         | A method that buffers logs but has no `Triton.flush()` at the end of the handler/`execute`/`finally`.                                                              |
| **Un-logged entry points**              | `@AuraEnabled`, REST, Queueable `execute`, Batch `start`/`finish` with no logging at all.                                                                          |
| **Flow fault paths with no Log action** | A `<faultConnector>` with no `TritonFlow` action — unhandled Flow errors going unseen.                                                                             |

### Judgment findings — flagged, not failed

* **Ad-hoc taxonomy strings** — `.area('...')` / `.type('...')` literals where an enum value exists, hinting at drift.
* **Honesty of levels** — `ERROR` used for non-failures, or loop chatter above `FINE`.
* **Missing context** — record-oriented logs with no `.relatedObject(s)`; callouts with no `.integrationPayload(...)`.
* **Low-comfort code** — old, untested, business-critical files that a rollout should treat gently (see the [comfort tiers](https://triton.pharos.ai/triton-best-practices/legacy-migration.md#start-by-assessing-your-comfort-with-the-code)).
* **Publishes in managed-package-object triggers** — `Triton.logNow(...)`, `Triton.flush()`, or `Triton.flushTop()` on a path reached from a trigger on another package's object (an SObject name carrying that package's namespace). The write belongs to the package, often under an integration user you can't test as. Triton 2.0.0 and later never throws on a failed publish, but an exhausted governor limit still fails the write, and a copy of Triton vendored before 2.0.0 does throw. The audit notes the Triton version it found and recommends `Triton.log(...)` plus one `Triton.flush()` as the handler's last statement, and the restricted-user test from [Instrument Apex](https://triton.pharos.ai/instrumentation-skills/instrument-apex.md#trigger-handlers-logging-never-fails-the-write).

{% hint style="info" %}
The audit uses the same static, grep-level signals the [CI guardrails](https://triton.pharos.ai/instrumentation-skills/setup-standards.md) use, plus structural analysis (it parses classes and flows, not just text). The hard findings are exactly what you'd want to block in CI; the judgment findings are what a reviewer should eyeball.
{% endhint %}

## The report

The default Markdown report leads with a scoreboard, then the prioritized plan, then the detail.

{% code lineNumbers="true" %}

```
Triton logging audit — force-app/main/default

Coverage
  Apex     62/141 instrumented (44%) · 79 gaps
  LWC       9/40  instrumented (23%) · 31 gaps
  Flows     4/22  instrumented (18%) · 18 gaps

Hard findings (block-worthy)
  System.debug ............ 213 occurrences in 47 classes
  Triton.instance (1.x) ... 12 classes  → migrate-to-2.0
  catch-not-logged ........ 88 blocks
  missing flush ........... 34 methods
  un-logged entry points .. 51
  flow faults unlogged .... 15

Suggested order (by value/risk)
  Phase 1 — entry points .. 51 files  (start here)
  Phase 2 — internals ..... 63 files
  Phase 3 — sweep ......... 40 files
  Deferred (low-comfort) .. 8 files   (review by hand)

Next: /pharos:instrument-org --phase 1
```

{% endcode %}

The `json` format emits the same data as structured findings (file, line, rule, severity) so you can gate CI or feed a dashboard.

## Where this fits

`audit-logging` is the front door of the whole workflow:

1. **Audit** — run this, read the report. *(read-only)*
2. **Fix version drift** — [`migrate-to-2.0`](https://triton.pharos.ai/instrumentation-skills/migrate-to-2.0.md) on anything using the 1.x singleton.
3. **Instrument** — [`instrument-org`](https://triton.pharos.ai/instrumentation-skills/instrument-org.md) works the prioritized plan.
4. **Lock it in** — [`setup-standards`](https://triton.pharos.ai/instrumentation-skills/setup-standards.md) wires the hard findings into CI so gaps can't creep back.

{% hint style="success" %}
**Re-run it as a ratchet.** With `--fail-on error,debug` in CI, the audit becomes a regression gate: once you've cleared `System.debug` and un-logged catches from an area, the build fails if they come back.
{% endhint %}

## Where to go next

* [Instrument the Org](https://triton.pharos.ai/instrumentation-skills/instrument-org.md) — act on the plan this audit produces.
* [Standards Enforcement](https://triton.pharos.ai/triton-best-practices/standards-enforcement.md) — the checklist and CI rules these checks come from.
* [Set Up Standards](https://triton.pharos.ai/instrumentation-skills/setup-standards.md) — turn the hard findings into automated guardrails.
* [Migrate to 2.0](https://triton.pharos.ai/instrumentation-skills/migrate-to-2.0.md) — clear the `Triton.instance` findings.
