Logger icon indicating copy to clipboard operation
Logger copied to clipboard

Add option to do an apex.debug call automatically when calling logger.log

Open martindsouza opened this issue 7 years ago • 6 comments

Clients would like to see their logs logged in APEX at the same time. This is redundant but helps when looking at the session debug in APEX.

Thanks to @dgielis for suggestion

  • [ ] Optional parameter
  • [ ] Need to verify how apex.debug changes in each version of APEX
  • [ ] Test to see the affects of when apex.debug is enabled vs disabled. This should not affect calls to logger.log

martindsouza avatar Jun 11 '18 13:06 martindsouza

@dgielis How do you think I should handle the following situation:

  • Logger level is set to error (i.e. similar to production situation)
  • APEX developer logs in and runs their app in APEX debug mode

Should calls to logger.log be logged? If yes then we'd need to factor the following:

  • How APEX levels map to Logger levels
  • When checking if a statement should be logged need to check both Logger and APEX levels
    • Need to check performance impacts of this
    • This would need to be triggered by session specific logging
    • Would need to "turn this off" when APEX debug is off.

martindsouza avatar Jun 18 '18 15:06 martindsouza

apex_debug, by default, does not store a log message if the page is not rendered in debug mode, or if the p_level is greater than the selected apex debug messaging level (there is an optional "force" parameter that can override this but you would not use it).

https://docs.oracle.com/database/apex-5.1/AEAPI/MESSAGE-Procedure.htm#AEAPI29228 https://docs.oracle.com/database/apex-5.1/AEAPI/Constants-2.htm#AEAPI29184

Suggested mapping:

if logger_level = g_permanent then

  /* apex_debug.error always logs, even if debug mode is turned off */
  apex_debug.error(p_message => l_message);

else

  l_apex_level :=
    case logger_level
    when g_error       then apex_debug.c_log_level_error /* [level 1] */
    when g_warning     then apex_debug.c_log_level_warn /* [level 2] */
    when g_information then apex_debug.c_log_level_info /* [level 4] */
                       else apex_debug.c_log_level_app_trace /* [level 6] */
    end;
    /* not used: apex_debug.c_log_level_app_enter [level 5] */

  apex_debug.message
    (p_message => l_message
    ,p_level   => l_apex_level);

end if;

jeffreykemp avatar Jun 19 '18 00:06 jeffreykemp

Is this not a duplicate of https://github.com/OraOpenSource/Logger/issues/158?

jeffreykemp avatar Jun 19 '18 00:06 jeffreykemp

like the mapping of Jeff.

Also note that in APEX you can do apex_debug.message('hello %s','Martin'); How would that be translated into logger?

dgielis avatar Jun 19 '18 08:06 dgielis

This seems out of scope for Logger and tightly couples Logger to Apex (though I imaging conditional compilation would fix that). I would suggest a better solution would be to wrap logger and apex.debug calls in a custom procedure. I added a Logger call to our custom error logging procedure when we started using it.

eaolson avatar Jun 20 '18 12:06 eaolson

@dgielis How do you think I should handle the following situation:

Logger level is set to error (i.e. similar to production situation) APEX developer logs in and runs their app in APEX debug mode Should calls to logger.log be logged? If yes then we'd need to factor the following:

Here is how I think, it could work. If APEX logging is configured (logger_prefs), then two fairly independend logging checks need to be made. One for the primary logging mode, one for the apex logging mode.

The subprogram that is called (log_error vs. log_trace) decides the logging level. Currently we seem not to have direct access to the apex debug level. So it is not possible to use that inside logger directly. Fortunatly we don't need it. If logger.log_error is called, then also call apex_debug.error. If logger.log_trace is called, call apex_debug.trace. The call to the apex_debug subprograms must not be dependend on the logger log_level settings. They already do depend on the apex log level settings (internal logic).

Yes there will be a negative performance impact because for the additional subprogram call and the check for the apex log level.

The apex_debug calls of cause are rendered there using conditional compiling. So this negative performance effect would only exist in an apex environment. In most APEX applications this slight performance slowdown would be acceptable. Other environments where performance is extremely critical will not need to configure this apex_debug setting.

However it also means we can not easily configure this on an application level, unless we have a separate logger installation for each (apex) application.

SvenWeller avatar Jun 21 '18 15:06 SvenWeller