> ## Documentation Index
> Fetch the complete documentation index at: https://fhenix-docs-broken-sample-fixes.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Logging

> Inspect FHE operations in your Hardhat test output

The mock contracts log every FHE operation to the console. This shows exactly which operations your contracts perform during tests.

## What gets logged

Each FHE operation emits a formatted log entry showing the operation name, the input and output operand hashes (truncated), and the security zone:

```text theme={null}
┌──────────────────┬──────────────────────────────────────────────────
│ [COFHE-MOCKS]    │ "counter.increment()" logs:
├──────────────────┴──────────────────────────────────────────────────
├ FHE.add          | euint32(4473..3424)[0] + euint32(1157..3648)[1]  =>  euint32(1106..1872)[1]
├ FHE.allowThis    | euint32(1106..1872)[1] -> 0x663f..6602
├ FHE.allow        | euint32(1106..1872)[1] -> 0x3c44..93bc
└─────────────────────────────────────────────────────────────────────
```

## `withLogs(name, fn)` (recommended)

Wraps a block of code with logging enabled and prints a labeled box around the output. The `name` appears as the header so you can identify which call produced which operations.

```typescript theme={null}
import hre from 'hardhat';

await hre.cofhe.mocks.withLogs('counter.increment()', async () => {
  await counter.increment();
});
```

`withLogs` enables logging before the closure runs and disables it after, so only operations from within that block appear in the output.

## `enableLogs()` / `disableLogs()` (manual)

For finer-grained control, you can enable and disable logging manually:

```typescript theme={null}
import hre from 'hardhat';

await hre.cofhe.mocks.enableLogs('counter.increment()');

await counter.increment();

await hre.cofhe.mocks.disableLogs();
```

<Info>
  `enableLogs` accepts an optional label string. If provided, it prints a labeled header immediately, useful when you want to mark a section of output at a known point.
</Info>

## Default logging behavior

Logging is **enabled by default**: `MockTaskManager` ships with its `logOps` flag set to `true`, so every FHE operation prints from the moment the mocks are deployed.

The flag lives onchain, not in your Hardhat config. Every control below is a transaction that flips `logOps` on the deployed `MockTaskManager`, which is why the setting resets each time the mocks are redeployed.

To silence logs for a whole test suite, disable them once in a global setup hook:

```typescript test/setup.ts theme={null}
import hre from 'hardhat';

before(async () => {
  await hre.cofhe.mocks.disableLogs();
});
```

Or toggle logging for a specific run using the Hardhat task:

```bash theme={null}
npx hardhat task:cofhe-mocks:setlogops --enable true
npx hardhat task:cofhe-mocks:setlogops --enable false
```

<Warning>
  There is no Hardhat config option for this. The plugin's config type still accepts a `cofhe.logMocks` boolean, but no plugin code reads it. Setting it has no effect on FHE-op logging. Use `disableLogs()` or the `setlogops` task instead.
</Warning>
