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

# Logging

> Print the FHE operations your contracts perform in Hardhat 3 test output

The mock `MockTaskManager` can print every FHE operation it runs. Under Hardhat 3 this logging is off until you turn it on, so wrap the code you want to inspect in `withLogs`.

## What gets logged

Each FHE operation prints one line with the operation name, its inputs, and its result. Each handle is shortened and followed, in brackets, by the plaintext the mock stores for it:

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

## Log one block with `withLogs`

`cofhe.mocks.withLogs(name, fn)` turns logging on, runs `fn`, and prints `name` as the header of the block:

```typescript theme={null}
await cofhe.mocks.withLogs('counter.increment()', async () => {
  await counter.write.increment();
});
```

When `fn` returns or throws, `withLogs` closes the block and turns logging back off if it was off before.

## Turn logging on and off

`enableLogs(label?)` and `disableLogs()` leave logging on across several calls:

```typescript theme={null}
await cofhe.mocks.enableLogs('counter.increment()');

await counter.write.increment();
await counter.write.increment();

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

The optional label prints a header immediately, so you can find the section in the output.

## Why logging starts off

The logging switch is the `logOps` flag in `MockTaskManager` storage. The contract declares it `true`, but that default is set by the constructor. The plugin places `MockTaskManager` with `hardhat_setCode`, which skips the constructor, so the flag starts as `false` on every new connection.

Because the flag lives onchain, each helper above is a transaction on the current chain, and every new connection starts with logging off again.

<Warning>
  The config type accepts `cofhe.logMocks`, but no plugin code reads it. Setting it to `true` does not turn logging on.
</Warning>

The `cofhe:set-log-ops` task also flips the flag, but it opens a connection of its own. Against the in-process network that is a separate chain, so the task does not affect your tests. Use the helpers above instead.
