# Using APEX_DEBUG to Diagnose Oracle APEX Issues

Oracle APEX offers robust debugging tools that help devs identify issues, optimize performance, and ensure smooth user experiences. The `apex_debug` package is central to this, providing detailed insight into your app’s behavior at runtime. Here’s a practical guide to using `apex_debug` and related features for debugging and tuning your APEX apps.

How to enable APEX\_DEBUG?  
  
There are several ways to enable debug mode in APEX:

**Developer toolbar:** Click the "debug" button in the developer toolbar while running your application.

**URL parameter:** Append `&p_debug=YES` or `&p_debug=LEVEL` (where level is 1–9) to your application URL for different verbosity levels.

**Application property:** Set the application’s debug property to "yes" for persistent debug logging.

**APEX\_DEBUG API:** Use `apex_debug.enable` in PL/SQL to programmatically enable debugging for a session.

## **Logging Dynamic Values and Parameters**

```sql
apex_debug.info('My Debug message, showing order_id: %s', p_order_id);
apex_debug.warn('unexpected status: %s', p_status);
apex_debug.error('Warning, my debug error: %s', sqlerrm);
```

| **Procedure** | **Purpose & Level** | **When to Use** |
| --- | --- | --- |
| `apex_debug.error` | Level 1 (Critical error) | For logging critical errors or failures that require immediate attention or may halt processing. |
| `apex_debug.warn` | Level 2 (Warning) | For logging important, non-critical issues that should be reviewed but do not stop processing. |
| `apex_`[`debug.info`](http://debug.info) | Level 4 (Informational, default level) | For routine information, such as variable values, process steps, or general progress messages. |
| `apex_debug.trace` | Level 6 (Trace) | For detailed, low-level tracing of code execution, such as inside loops or complex logic blocks. |

## **View the debug messages**

To view the debug messages, click on "View Debug" in the dev toolbar, or go to Utilities / Debug Messages, or also running the following query:

```sql
select *
from apex_debug_messages
```

## **Logging in Loops and Bulk Operations**

Be careful when logging too many messages, for example, inside a loop. Be aware of APEX flood control, which limits the number of debug messages per page view (the default is 50,000).

You can check this limit with the query below (run as sys).  

```sql
select *
from APEX_INSTANCE_PARAMETERS
where name = 'DEBUG_MESSAGE_PAGE_VIEW_LIMIT';
```

## **Debugging Outside APEX Applications**

You can use `apex_debug` in standalone PL/SQL scripts or jobs:

```sql
apex_session.create_session(p_app_id=>101, p_page_id=>1, p_username=>'RODRIGO');
apex_debug.enable(apex_debug.c_log_level_info);
apex_debug.info('My debug message from sql developer');
apex_session.detach;
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748015448351/849c2801-35e6-4618-a703-a0126414323b.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748015510521/1466fd89-ae4e-4461-85ae-b282a7dc0477.png align="center")

The APEX debug feature is very powerful and useful. To help you troubleshoot issues, enable debug mode and use the browser’s developer tools to inspect AJAX calls and dynamic actions. The debug log will display the sequence and timing of events, helping you identify problems with client-side interactivity.
