Logger 3.1.0: Adding Level to Additional Procedures

Prior to Logger 3.1.0, the following procedures would only log data when the Logger level was set to DEBUG:

  • log_apex_items
  • log_userenv
  • log_cgi_env
  • log_character_codes

This introduced an additional issue. What happens when I want to call these functions when the Logger level was set to ERROR? For example, suppose in a production environment you set the Logger level to ERROR (this is a pretty standard case). When an error occurs you call the usual logger.log_error call in the exception block. What if you wanted to also log all the APEX item values? If you called logger.log_apex_items it would not run since it had a hard coded validation to only log in DEBUG mode.

Each of the above functions now take in a new optional parameter called p_level. If defined, it will always log up to the defined level and store the entry in LOGGER_LOGS as that level. The best way to think of this paramater is if it is defined you're calling the equivialnt of logger.log_apex_items_error (if p_level => logger.g_error). If it is not defined, it will continue to only log in DEBUG mode and use the associated value for logger_level in LOGGER_LOGS.

Example:

-- Dev environment where Logger level is "DEBUG"
exec logger.set_level(p_level => logger.g_debug);

exec logger.log_userenv;

select id, logger_level, substr(text, 1, 45) text
from logger_logs_5_min
order by id desc;

-- Note: The "64" refers to the "SYS_CONTEXT" level. See the API docs for more info
        ID LOGGER_LEVEL TEXT
---------- ------------ ---------------------------------------------
    890647           64 USERENV values stored in the EXTRA column


-- Production: Logger level is set to "ERROR"
exec logger.set_level(p_level => logger.g_error);
exec logger.log_userenv;

-- No rows will be returned since Logger level is "ERROR"
select id, logger_level, substr(text, 1, 45) text
from logger_logs_5_min
order by id desc;

no rows selected


-- Using new parameter, store log_userenv even when Logger level is "ERROR"
exec logger.log_userenv(p_level => logger.g_error);

select id, logger_level, substr(text, 1, 45) text
from logger_logs_5_min
order by 1 desc;

-- Note: The "2" refers to the "ERROR" level. This happens since it uses the value stored in p_level
        ID LOGGER_LEVEL TEXT
---------- ------------ ---------------------------------------------
    890648            2 USERENV values stored in the EXTRA column