# Debugging and Emitting Debug Events

The modules provide `emit_debug_event` functions or dedicated `DebugEvent` structures to help you trace what’s happening inside your code during development and testing.

**How to Use Debug Events**:

* Insert calls to `emit_debug_event(key, value)` at critical points in your code—such as right before a trade price calculation or after updating a deny list.
* By reviewing emitted debug events in test outputs or the Sui CLI logs, you can pinpoint the exact stage at which unexpected behavior occurs.

**Best Practices**:

* **Strategic Placement**: Only add debug events around complex logic (e.g., minting large batches, performing swaps in TRADE) to avoid cluttering your output.
* **Remove or Comment Out**: Once your code is stable, remove or comment out extra debug events to keep production logs clean.

**Example**:

```move
emit_debug_event("liquidity_add", "User is adding 50 NFTs and 1000 tokens");
```

This line emits a `DebugEvent` that you can see in test logs, helping you confirm that the liquidity addition flow is triggered correctly.

***

By running unit tests frequently, understanding common issues, and leveraging debug events for granular tracing, you can identify and resolve problems efficiently. This proactive approach to testing and troubleshooting ensures the integrity and stability of your Artinals-based NFT platform, enhancing user trust and maintaining a reliable marketplace experience.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.artinals.com/artinals-protocol/testing-and-troubleshooting/debugging-and-emitting-debug-events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
