APEX_APPLICATION.G_DEBUG
The APEX_APPLICATION package enables users to take advantage of global variables. The apex_application.g_debug variable refers to whether debugging is currently switched on or off. Valid values for this variable are TRUE or FALSE.
Turning debug ON shows details about application processing.
For example:
IF apex_application.g_debug THEN 
  apex_debug_message.log_message('Custom Validation'); 
END IF;Including the preceding code in the APEX page, anywhere where PL/SQL is allowed, will add information visible in APEX_DEBUG_MESSAGES, and therefore in the View Debug page. This information will only be added when apex_application.g_debug evaluates to TRUE.
The debug Advanced Programming Interface (API)
The APEX_DEBUG_MESSAGE package provides utility functions for managing the debug message log. Specifically, this package provides the necessary APIs to instrument and debug PL/SQL code contained within the APEX application as well as the PL/SQL code in database stored procedures...