Index | Installation | Introduction | API Overview | Package Console | Changelog | Uninstallation
NOTE: This method overview is generated from the package specification in sources/CONSOLE.pks
.
- Package console
- Function my_client_identifier
- Function my_log_level
- Procedure error_save_stack
- Procedure error
- Function error
- Procedure warn
- Function warn
- Procedure info
- Function info
- Procedure log
- Function log
- Procedure debug
- Function debug
- Procedure trace
- Function trace
- Procedure count
- Procedure count_reset
- Procedure count_current
- Procedure count_end
- Function count_current
- Function count_end
- Procedure time
- Procedure time_reset
- Procedure time_current
- Procedure time_end
- Function time_current
- Function time_end
- Procedure table#
- Procedure assert
- Procedure assertf
- Procedure add_param
- Function format
- Procedure action
- Procedure module
- Function level_error
- Function level_warning
- Function level_info
- Function level_debug
- Function level_trace
- Function level_is_warning
- Function level_is_info
- Function level_is_debug
- Function level_is_trace
- Function level_is_warning_yn
- Function level_is_info_yn
- Function level_is_debug_yn
- Function level_is_trace_yn
- Function apex_error_handling
- Function apex_plugin_render
- Function apex_plugin_ajax
- Procedure conf
- Procedure init
- Procedure init
- Procedure exit
- Procedure exit_all
- Function version
- Procedure generate_param_trace
- Function split_to_table
- Function split
- Function join
- Function to_yn
- Function to_string
- Function to_bool
- Function to_html_table
- Function to_md_code_block
- Function to_md_tab_header
- Function to_md_tab_data
- Function to_unibar
- Procedure print
- Procedure printf
- Function runtime
- Function runtime_seconds
- Function runtime_milliseconds
- Function level_name
- Function scope
- Function call_stack
- Function apex_env
- Function cgi_env
- Function user_env
- Function console_env
- Procedure clob_append
- Procedure clob_append
- Procedure clob_flush_cache
- Function status
- Function conf
- Function client_prefs
- Procedure purge
- Procedure purge_all
- Procedure purge_job_create
- Procedure purge_job_drop
- Procedure purge_job_enable
- Procedure purge_job_disable
- Procedure purge_job_run
An instrumentation tool for Oracle developers. Save to install on production and mostly API compatible with the JavaScript console.
For more infos have a look at the project page on GitHub.
SIGNATURE
package console authid definer is
c_name constant varchar2 ( 30 byte ) := 'Oracle Instrumentation Console' ;
c_version constant varchar2 ( 10 byte ) := '1.1.1' ;
c_url constant varchar2 ( 36 byte ) := 'https://github.com/ogobrecht/console' ;
c_license constant varchar2 ( 3 byte ) := 'MIT' ;
c_author constant varchar2 ( 15 byte ) := 'Ottmar Gobrecht' ;
Returns the current session identifier of the own session. This information is cached in a package variable and determined on package initialization.
select console.my_client_identifier from dual;
SIGNATURE
function my_client_identifier return varchar2;
Returns the current log level of the own session. This information is cached in a package variable for performance reasons and re-evaluated every 10 seconds.
select console.my_log_level from dual;
SIGNATURE
function my_log_level return integer;
Saves the error stack, so that you are able to handle the error on the most outer point in your code without loosing detail information of the original error nested deeper in your code.
With this method we try to prevent log spoiling - if you use it right you can have ONE log entry for your errors with the saved details where the error occured.
EXAMPLE
set define off
set feedback off
set serveroutput on
set linesize 120
set pagesize 40
column call_stack heading "Call Stack" format a120
whenever sqlerror exit sql.sqlcode rollback
prompt TEST ERROR_SAVE_STACK
prompt - compile package spec
create or replace package some_api is
procedure do_stuff;
end;
/
prompt - compile package body
create or replace package body some_api is
------------------------------------------------------------------------------
procedure do_stuff is
--------------------------------------
procedure sub1 is
--------------------------------------
procedure sub2 is
--------------------------------------
procedure sub3 is
begin
console.assert(1 = 2, 'Demo');
exception --sub3
when others then
console.error_save_stack;
raise;
end;
--------------------------------------
begin
sub3;
exception --sub2
when others then
console.error_save_stack;
raise;
end;
--------------------------------------
begin
sub2;
exception --sub1
when others then
console.error_save_stack;
raise no_data_found;
end;
--------------------------------------
begin
sub1;
exception --do_stuff
when others then
console.error;
raise;
end;
------------------------------------------------------------------------------
end;
/
prompt - call the package
begin
some_api.do_stuff;
exception
when others then
null; --> I know, I know, never do that without a final raise...
--> But we want only test our logging without killing the script run...
end;
/
prompt - FINISHED, selecting now the call stack from the last log entry...
select call_stack from console_logs order by log_id desc fetch first row only;
EXAMPLE OUTPUT
TEST ERROR_SAVE_STACK
- compile package spec
- compile package body
- call the package
- FINISHED, selecting now the call stack from the last log entry...
Call Stack
------------------------------------------------------------------------------------------------------------------------
#### Saved Error Stack
- PLAYGROUND.SOME_API.DO_STUFF.SUB1.SUB2.SUB3, line 14 (line 11, ORA-20777 Assertion failed: Demo)
- PLAYGROUND.SOME_API.DO_STUFF.SUB1.SUB2, line 22 (line 19)
- PLAYGROUND.SOME_API.DO_STUFF.SUB1, line 30 (line 27)
- PLAYGROUND.SOME_API.DO_STUFF, line 38 (line 35, ORA-01403 no data found)
#### Call Stack
- PLAYGROUND.SOME_API.DO_STUFF, line 38
- __anonymous_block, line 2
#### Error Stack
- ORA-01403 no data found
- ORA-06512 at "PLAYGROUND.SOME_API", line 31
- ORA-20777 Assertion failed: Test assertion with line break.
- ORA-06512 at "PLAYGROUND.SOME_API", line 23
- ORA-06512 at "PLAYGROUND.SOME_API", line 15
- ORA-06512 at "PLAYGROUND.CONSOLE", line 750
- ORA-06512 at "PLAYGROUND.SOME_API", line 11
- ORA-06512 at "PLAYGROUND.SOME_API", line 19
- ORA-06512 at "PLAYGROUND.SOME_API", line 27
#### Error Backtrace
- PLAYGROUND.SOME_API, line 31
- PLAYGROUND.SOME_API, line 23
- PLAYGROUND.SOME_API, line 15
- PLAYGROUND.CONSOLE, line 750
- PLAYGROUND.SOME_API, line 11
- PLAYGROUND.SOME_API, line 19
- PLAYGROUND.SOME_API, line 27
- PLAYGROUND.SOME_API, line 35
SIGNATURE
procedure error_save_stack;
Log a message with the level 1 (error).
SIGNATURE
procedure error (
p_message in clob default null , -- The log message itself
p_permanent in boolean default false , -- Should the log entry be permanent (not deleted by purge methods)
p_call_stack in boolean default true , -- Include call stack
p_apex_env in boolean default false , -- Include APEX environment
p_cgi_env in boolean default false , -- Include CGI environment
p_console_env in boolean default false , -- Include Console environment
p_user_env in boolean default false , -- Include user environment
p_user_agent in varchar2 default null , -- User agent of browser or other client technology
p_user_scope in varchar2 default null , -- Override PL/SQL scope
p_user_error_code in integer default null , -- Override PL/SQL error code
p_user_call_stack in varchar2 default null -- Override PL/SQL call stack
);
Log a message with the level 1 (error). Returns the log ID.
SIGNATURE
function error (
p_message in clob default null ,
p_permanent in boolean default false ,
p_call_stack in boolean default true ,
p_apex_env in boolean default false ,
p_cgi_env in boolean default false ,
p_console_env in boolean default false ,
p_user_env in boolean default false ,
p_user_agent in varchar2 default null ,
p_user_scope in varchar2 default null ,
p_user_error_code in integer default null ,
p_user_call_stack in varchar2 default null )
return console_logs.log_id%type;
Log a message with the level 2 (warning).
SIGNATURE
procedure warn (
p_message in clob default null ,
p_permanent in boolean default false ,
p_call_stack in boolean default false ,
p_apex_env in boolean default false ,
p_cgi_env in boolean default false ,
p_console_env in boolean default false ,
p_user_env in boolean default false ,
p_user_agent in varchar2 default null ,
p_user_scope in varchar2 default null ,
p_user_error_code in integer default null ,
p_user_call_stack in varchar2 default null );
Log a message with the level 2 (warning). Returns the log ID.
SIGNATURE
function warn (
p_message in clob default null ,
p_permanent in boolean default false ,
p_call_stack in boolean default false ,
p_apex_env in boolean default false ,
p_cgi_env in boolean default false ,
p_console_env in boolean default false ,
p_user_env in boolean default false ,
p_user_agent in varchar2 default null ,
p_user_scope in varchar2 default null ,
p_user_error_code in integer default null ,
p_user_call_stack in varchar2 default null )
return console_logs.log_id%type;
Log a message with the level 3 (info).
SIGNATURE
procedure info (
p_message in clob default null ,
p_permanent in boolean default false ,
p_call_stack in boolean default false ,
p_apex_env in boolean default false ,
p_cgi_env in boolean default false ,
p_console_env in boolean default false ,
p_user_env in boolean default false ,
p_user_agent in varchar2 default null ,
p_user_scope in varchar2 default null ,
p_user_error_code in integer default null ,
p_user_call_stack in varchar2 default null );
Log a message with the level 3 (info). Returns the log ID.
SIGNATURE
function info (
p_message in clob default null ,
p_permanent in boolean default false ,
p_call_stack in boolean default false ,
p_apex_env in boolean default false ,
p_cgi_env in boolean default false ,
p_console_env in boolean default false ,
p_user_env in boolean default false ,
p_user_agent in varchar2 default null ,
p_user_scope in varchar2 default null ,
p_user_error_code in integer default null ,
p_user_call_stack in varchar2 default null )
return console_logs.log_id%type;
Log a message with the level 3 (info).
SIGNATURE
procedure log (
p_message in clob default null ,
p_permanent in boolean default false ,
p_call_stack in boolean default false ,
p_apex_env in boolean default false ,
p_cgi_env in boolean default false ,
p_console_env in boolean default false ,
p_user_env in boolean default false ,
p_user_agent in varchar2 default null ,
p_user_scope in varchar2 default null ,
p_user_error_code in integer default null ,
p_user_call_stack in varchar2 default null );
Log a message with the level 3 (info). Returns the log ID.
SIGNATURE
function log (
p_message in clob default null ,
p_permanent in boolean default false ,
p_call_stack in boolean default false ,
p_apex_env in boolean default false ,
p_cgi_env in boolean default false ,
p_console_env in boolean default false ,
p_user_env in boolean default false ,
p_user_agent in varchar2 default null ,
p_user_scope in varchar2 default null ,
p_user_error_code in integer default null ,
p_user_call_stack in varchar2 default null )
return console_logs.log_id%type;
Log a message with the level 4 (debug).
SIGNATURE
procedure debug (
p_message in clob default null ,
p_permanent in boolean default false ,
p_call_stack in boolean default false ,
p_apex_env in boolean default false ,
p_cgi_env in boolean default false ,
p_console_env in boolean default false ,
p_user_env in boolean default false ,
p_user_agent in varchar2 default null ,
p_user_scope in varchar2 default null ,
p_user_error_code in integer default null ,
p_user_call_stack in varchar2 default null );
Log a message with the level 4 (debug). Returns the log ID.
SIGNATURE
function debug (
p_message in clob default null ,
p_permanent in boolean default false ,
p_call_stack in boolean default false ,
p_apex_env in boolean default false ,
p_cgi_env in boolean default false ,
p_console_env in boolean default false ,
p_user_env in boolean default false ,
p_user_agent in varchar2 default null ,
p_user_scope in varchar2 default null ,
p_user_error_code in integer default null ,
p_user_call_stack in varchar2 default null )
return console_logs.log_id%type;
Log a message with the level 5 (trace).
SIGNATURE
procedure trace (
p_message in clob default null ,
p_permanent in boolean default false ,
p_call_stack in boolean default true ,
p_apex_env in boolean default true ,
p_cgi_env in boolean default true ,
p_console_env in boolean default true ,
p_user_env in boolean default true ,
p_user_agent in varchar2 default null ,
p_user_scope in varchar2 default null ,
p_user_error_code in integer default null ,
p_user_call_stack in varchar2 default null );
Log a message with the level 5 (trace). Returns the log ID.
SIGNATURE
function trace (
p_message in clob default null ,
p_permanent in boolean default false ,
p_call_stack in boolean default true ,
p_apex_env in boolean default true ,
p_cgi_env in boolean default true ,
p_console_env in boolean default true ,
p_user_env in boolean default true ,
p_user_agent in varchar2 default null ,
p_user_scope in varchar2 default null ,
p_user_error_code in integer default null ,
p_user_call_stack in varchar2 default null )
return console_logs.log_id%type;
Creates a new counter with a value of one or adds one to an existing counter.
Does not depend on a log level, can be used anywhere to count things.
EXAMPLE
declare
v_counter varchar2(30) := 'Processing xyz';
begin
for i in 1 .. 10 loop
console.count(v_counter);
end loop;
console.count_current(v_counter); -- without optional message
for i in 1 .. 100 loop
console.count(v_counter);
end loop;
console.count_current(v_counter, 'end of step two');
for i in 1 .. 1000 loop
console.count(v_counter);
end loop;
console.count_end(v_counter, 'end of step three');
end;
/
This will produce the following log messages in the table CONSOLE_LOGS when your current log level is 3 (info) or higher:
- Processing xyz: 10
- Processing xyz: 110 - end of step two
- Processing xyz: 1110 - end of step three
SIGNATURE
procedure count ( p_label in varchar2 default null );
Reset an existing counter or create a new one.
Does not depend on a log level, can be used anywhere to count things.
Also see procedure count
above.
SIGNATURE
procedure count_reset ( p_label in varchar2 default null );
Log the current value of a counter, if the sessions log level is greater or equal 3 (info).
Also see procedure count
above.
SIGNATURE
procedure count_current (
p_label in varchar2 default null ,
p_message in varchar2 default null );
Log the current value of a counter, if the sessions log level is greater or equal 3 (info). Delete the counter.
Also see procedure count
above.
SIGNATURE
procedure count_end (
p_label in varchar2 default null ,
p_message in varchar2 default null );
Returns the current counter value or null, if the given label does not exist.
Does not depend on a log level, can be used anywhere to count things.
Also see procedure count
above. The following example does not use the
optional label, therefore the implicit label used in the background will be
default
. As we get only the value back from the funtion and we need only one
counter at the same time this is ok for us here and it keeps the code simple.
EXAMPLE
set serveroutput on
begin
console.print('Counting nonsense...');
for i in 1 .. 1000 loop
if mod(i, 3) = 0 then
console.count;
end if;
end loop;
console.printf('Current value: %s', console.count_current );
console.count_reset;
for i in 1 .. 10 loop
console.count;
end loop;
console.printf('Final value: %s', console.count_end );
end;
/
This will print something like the following to the server output:
Counting nonsense...
Current value: 333
Final value: 10
SIGNATURE
function count_current (
p_label in varchar2 default null )
return t_int;
Returns the current counter value or null, if the given label does not exist. Deletes the counter.
Does not depend on a log level, can be used anywhere to count things.
Also see function count_current
above.
SIGNATURE
function count_end (
p_label in varchar2 default null )
return t_int;
Create and a new timer. If the timer is already existing it will start again with the current local timestamp.
Does not depend on a log level, can be used anywhere to measure runtime.
EXAMPLE
declare
v_timer varchar2(30) := 'Processing xyz';
begin
--basic usage
console.time;
sys.dbms_session.sleep(0.1);
console.time_end; -- without optional label and message
console.time(v_timer);
sys.dbms_session.sleep(0.1);
console.time_current(v_timer); -- without optional message
sys.dbms_session.sleep(0.1);
console.time_current(v_timer, 'end of step two');
sys.dbms_session.sleep(0.1);
console.time_end(v_timer, 'end of step three');
end;
/
This will produce the following log messages in the table CONSOLE_LOGS when your current log level is 3 (info) or higher:
- default: 00:00:00.102508
- Processing xyz: 00:00:00.108048
- Processing xyz: 00:00:00.212045 - end of step two
- Processing xyz: 00:00:00.316084 - end of step three
SIGNATURE
procedure time ( p_label in varchar2 default null );
Reset an existing timer or create a new one.
Does not depend on a log level, can be used anywhere to measure runtime.
Also see procedure time
above.
SIGNATURE
procedure time_reset ( p_label in varchar2 default null );
Log the elapsed time, if the sessions log level is greater or equal 3 (info).
Can be called multiple times - use console.time_end
to log the elapsed time
and delete the timer.
Also see procedure time
above.
SIGNATURE
procedure time_current (
p_label in varchar2 default null ,
p_message in varchar2 default null );
Log the elapsed time and delete the timer, if the sessions log level is greater or equal 3 (info).
Also see procedure time
above.
SIGNATURE
procedure time_end (
p_label in varchar2 default null ,
p_message in varchar2 default null );
Returns the elapsed time as varchar in the format 00:00:00.000000 or null, if the given label does not exist.
Does not depend on a log level, can be used anywhere to measure runtime.
Can be called multiple times - use console.time_end
to return the elapsed time
and delete the timer.
Also see procedure time
above. The following example does not use the optional
label, therefore the implicit label used in the background will be default
. As
we get only the runtime back from the funtion in the format 00:00:00.000000 and
we need only one timer at the same time this is ok for us here and it keeps the
code simple.
EXAMPLE
set serveroutput on
begin
console.time;
console.print('Processing step one...');
sys.dbms_session.sleep(0.1);
console.printf('Elapsed time: %s', console.time_current);
console.print('Processing step two...');
sys.dbms_session.sleep(0.1);
console.printf('Elapsed time: %s', console.time_current);
console.print('Processing step three...');
sys.dbms_session.sleep(0.1);
console.printf('Elapsed time: %s', console.time_end);
end;
/
This will result in something like the following output:
Processing step one...
Elapsed time: 00:00:00.105398
Processing step two...
Elapsed time: 00:00:00.209267
Processing step three...
Elapsed time: 00:00:00.313301
SIGNATURE
function time_current ( p_label in varchar2 default null ) return varchar2;
Returns the elapsed time as varchar in the format 00:00:00.000000 or null, if the given label does not exist. Deletes the timer.
Does not depend on a log level, can be used anywhere to measure runtime.
Also see function time_current
above.
SIGNATURE
function time_end ( p_label in varchar2 default null ) return varchar2;
Logs a cursor as a HTML table with the level 3 (info).
Using a cursor for the table method is very flexible, but opening a cursor can produce unnecessary work for your system when you are not in the log level info. Therefore please check your current log level before you open the cursor.
EXAMPLE
declare
v_dataset sys_refcursor;
begin
-- Your business logic here...
-- Debug code
if console.level_is_info then
open v_dataset for
select table_name,
tablespace_name,
logging,
num_rows,
last_analyzed,
partitioned,
has_identity
from user_tables;
console.table#(v_dataset);
end if;
-- Your business logic here...
end;
/
SIGNATURE
procedure table# (
p_data_cursor in sys_refcursor ,
p_comment in varchar2 default null ,
p_include_row_num in boolean default true ,
p_max_rows in integer default 100 ,
p_max_column_length in integer default 1000 );
If the given expression evaluates to false, an error is raised with the given message.
EXAMPLE
declare
x number := 5;
y number := 3;
begin
console.assert(
x < y,
'x should be less then y (x=' || to_char(x) || ', y=' || to_char(y) || ')'
);
exception
when others then
console.error;
raise;
end;
/
SIGNATURE
procedure assert (
p_expression in boolean,
p_message in varchar2
);
If the given expression evaluates to false, an error is raised with the given formatted message.
EXAMPLE
declare
x number := 5;
y number := 3;
begin
console.assertf(
x < y,
'x should be less then y (x=%s, y=%s)',
to_char(x),
to_char(y)
);
exception
when others then
console.error;
raise;
end;
/
SIGNATURE
procedure assertf (
p_expression in boolean ,
p_message in varchar2 ,
p0 in varchar2 default null ,
p1 in varchar2 default null ,
p2 in varchar2 default null ,
p3 in varchar2 default null ,
p4 in varchar2 default null ,
p5 in varchar2 default null ,
p6 in varchar2 default null ,
p7 in varchar2 default null ,
p8 in varchar2 default null ,
p9 in varchar2 default null
);
Add a parameter to the package internal parameter collection which will be included in the next log call (error, warn, info, log, debug or trace)
The procedure is overloaded to support different parameter types.
VARCHAR and CLOB parameters are shortened to 2000 characters and additionally
escaped for Markdown table columns (replacing all line endings with whitespace
and the pipe character with |
). If you need your full parameter text then
please use the p_message
CLOB parameter in the log methods error, warn, info,
log, debug and trace to do your own parameter handling.
procedure add_param ( p_name in varchar2, p_value in varchar2 );
procedure add_param ( p_name in varchar2, p_value in number );
procedure add_param ( p_name in varchar2, p_value in date );
procedure add_param ( p_name in varchar2, p_value in timestamp );
procedure add_param ( p_name in varchar2, p_value in timestamp with time zone );
procedure add_param ( p_name in varchar2, p_value in timestamp with local time zone );
procedure add_param ( p_name in varchar2, p_value in interval year to month );
procedure add_param ( p_name in varchar2, p_value in interval day to second );
procedure add_param ( p_name in varchar2, p_value in boolean );
procedure add_param ( p_name in varchar2, p_value in clob );
procedure add_param ( p_name in varchar2, p_value in xmltype );
EXAMPLE
--create demo procedure
create or replace procedure demo_proc (
p_01 varchar2 ,
p_02 number ,
p_03 date ,
p_04 timestamp ,
p_05 timestamp with time zone ,
p_06 timestamp with local time zone ,
p_07 interval year to month ,
p_08 interval day to second ,
p_09 boolean ,
p_10 clob ,
p_11 xmltype )
is
begin
raise_application_error(-20999, 'Demo Error.');
exception
when others then
console.add_param('p_01', p_01);
console.add_param('p_02', p_02);
console.add_param('p_03', p_03);
console.add_param('p_04', p_04);
console.add_param('p_05', p_05);
console.add_param('p_06', p_06);
console.add_param('p_07', p_07);
console.add_param('p_08', p_08);
console.add_param('p_09', p_09);
console.add_param('p_10', p_10);
console.add_param('p_11', p_11);
console.error('Ooops, something went wrong');
raise;
end demo_proc;
/
--run demo procedure
begin
demo_proc (
p_01 => 'test vc2' ,
p_02 => 1.23 ,
p_03 => sysdate ,
p_04 => systimestamp ,
p_05 => systimestamp ,
p_06 => localtimestamp ,
p_07 => interval '4-2' year to month ,
p_08 => interval '7 6:12:42.123' day to second ,
p_09 => true ,
p_10 => to_clob('test clob') ,
p_11 => xmltype('<test_xml/>') );
end;
/
SIGNATURE
procedure add_param ( p_name in varchar2, p_value in varchar2 );
Formats a message with the following rules:
- Replace all occurrences of
%0
..%9
by id with the corresponding parametersp0
..p9
- Replace
%n
with new lines (line feed character) - Replace all occurrences of
%s
in positional order with the corresponding parameters using sys.utl_lms.format_message - also see the Oracle docs.
SIGNATURE
function format (
p_message in varchar2 ,
p0 in varchar2 default null ,
p1 in varchar2 default null ,
p2 in varchar2 default null ,
p3 in varchar2 default null ,
p4 in varchar2 default null ,
p5 in varchar2 default null ,
p6 in varchar2 default null ,
p7 in varchar2 default null ,
p8 in varchar2 default null ,
p9 in varchar2 default null )
return varchar2;
An alias for dbms_application_info.set_action.
Use the given action to set the session action attribute (in memory operation, does not log anything). This attribute is then visible in the system session views, the user environment and will be logged within all console logging methods.
When you set the action attribute with console.action
you should also reset it
when you have finished your work to prevent wrong info in the system and your
logging for subsequent method calls.
EXAMPLE
begin
console.action('My process/task');
-- do your stuff here...
console.action(null);
exception
when others then
console.error('something went wrong');
console.action(null);
raise;
end;
/
SIGNATURE
procedure action ( p_action in varchar2 );
An alias for dbms_application_info.set_module.
Use the given module and action to set the session module and action attributes (in memory operation, does not log anything). These attributes are then visible in the system session views, the user environment and will be logged within all console logging methods.
Please note that your app framework may set the module and you should consider
to only set the action attribute with the action
(see below).
SIGNATURE
procedure module (
p_module in varchar2,
p_action in varchar2 default null
);
Returns the number code for the level 1 error.
SIGNATURE
function level_error return integer;
Returns the number code for the level 2 warning.
SIGNATURE
function level_warning return integer;
Returns the number code for the level 3 info.
SIGNATURE
function level_info return integer;
Returns the number code for the level 4 debug.
SIGNATURE
function level_debug return integer;
Returns the number code for the level 5 trace.
SIGNATURE
function level_trace return integer;
Returns true when the level is greater than or equal warning, otherwise false.
SIGNATURE
function level_is_warning return boolean;
Returns true when the level is greater than or equal info, otherwise false.
SIGNATURE
function level_is_info return boolean;
Returns true when the level is greater than or equal debug, otherwise false.
SIGNATURE
function level_is_debug return boolean;
Returns true when the level is greater than or equal trace, otherwise false.
SIGNATURE
function level_is_trace return boolean;
Returns 'Y' when the level is greater than or equal warning, otherwise 'N'.
SIGNATURE
function level_is_warning_yn return varchar2;
Returns 'Y' when the level is greater than or equal info, otherwise 'N'.
SIGNATURE
function level_is_info_yn return varchar2;
Returns 'Y' when the level is greater than or equal debug, otherwise 'N'.
SIGNATURE
function level_is_debug_yn return varchar2;
Returns 'Y' when the level is greater than or equal trace, otherwise 'N'.
SIGNATURE
function level_is_trace_yn return varchar2;
You can register this example APEX error handler function to log APEX internal errors.
To do so go into the Application Builder into your app > Edit Application
Properties > Error Handling > Error Handling Function. You can then provide here
console.apex_error_handling
.
For more info see the official docs.
The implementation code (see package body) is taken from the docs and aligned for CONSOLE as a starting point. If this does not fit your needs then simply reimplement an own function and use that instead.
SIGNATURE
function apex_error_handling ( p_error in apex_error.t_error )
return apex_error.t_error_result;
Used for the APEX plugin to capture frontend JavaScript errors.
If you plan to use the plugin make sure you have either console installed in
your APEX parsing schema or a synonym named console
for it as this function is
referenced in the plug-in as a callback to console.apex_plugin_render
.
SIGNATURE
function apex_plugin_render (
p_dynamic_action in apex_plugin.t_dynamic_action ,
p_plugin in apex_plugin.t_plugin )
return apex_plugin.t_dynamic_action_render_result;
Used for the APEX plugin to capture frontend JavaScript errors.
If you plan to use the plugin make sure you have either console installed in
your APEX parsing schema or a synonym named console
for it as this function is
referenced in the plug-in as a callback to console.apex_plugin_ajax
.
SIGNATURE
function apex_plugin_ajax (
p_dynamic_action in apex_plugin.t_dynamic_action ,
p_plugin in apex_plugin.t_plugin )
return apex_plugin.t_dynamic_action_ajax_result;
Set the global console configuration.
DO NOT USE THIS PROCEDURE IN YOUR BUSINESS LOGIC. IT IS INTENDED ONLY FOR MANAGING GLOBAL PREFERENCES.
EXAMPLE
--set all sessions to level warning
exec console.conf(p_level => 2);
--or
exec console.conf(p_level => console.c_level_warning);
--set multiple options at once
begin
console.conf(
p_level => console.c_level_info,
p_check_interval => 10
);
end;
/
SIGNATURE
procedure conf (
p_level in integer default null , -- Level 1 (error), 2 (warning), 3 (info), 4 (debug) or 5 (trace).
p_check_interval in integer default null , -- The number of seconds a session looks for a changed configuration. Allowed values: 1 to 60 seconds.
p_enable_ascii_art in boolean default null -- Currently used to have more fun with the APEX error handling messages. But who knows...
);
Init/set the preferences for a specific session/client_identifier and duration.
To avoid spoiling the context with very long input the parameter p_client_identifier is truncated after 64 characters before using it.
For easier usage there is an overloaded procedure available which uses always your own session/client_identifier.
DO NOT USE THIS PROCEDURE IN YOUR BUSINESS LOGIC. IT IS INTENDED ONLY FOR MANAGING CLIENT PREFERENCES.
EXAMPLES
-- Dive into your own session with the default log level of 3 (info) and the
-- default duration of 60 (minutes).
exec console.init;
-- With level 4 (debug) for the next 15 minutes.
exec console.init(4, 15);
-- Using a constant for the level
exec console.init(console.c_level_debug, 90);
-- Debug an APEX session...
exec console.init('OGOBRECHT:8805903776765', 4, 90);
-- ...with named parameters
begin
console.init(
p_client_identifier => 'OGOBRECHT:8805903776765',
p_level => console.c_level_debug,
p_duration => 15
);
end;
/
SIGNATURE
procedure init (
p_client_identifier in varchar2 , -- The client identifier provided by the application or console itself.
p_level in integer default c_level_info , -- Level 2 (warning), 3 (info), 4 (debug) or 5 (trace).
p_duration in integer default c_duration_default , -- The number of minutes the session should be in client preferences mode. Allowed values: 1 to 1440 minutes (24 hours).
p_check_interval in integer default c_check_interval_default , -- The number of seconds a session looks for a changed configuration. Allowed values: 1 to 60 seconds.
p_call_stack in boolean default false , -- Should the call stack be included.
p_user_env in boolean default false , -- Should the user environment be included.
p_apex_env in boolean default false , -- Should the APEX environment be included.
p_cgi_env in boolean default false , -- Should the CGI environment be included.
p_console_env in boolean default false -- Should the console environment be included.
);
An overloaded procedure for easier initialization of the own session/client_identifier in an development IDE.
SIGNATURE
procedure init (
p_level in integer default c_level_info , -- Level 2 (warning), 3 (info), 4 (debug) or 5 (trace).
p_duration in integer default c_duration_default , -- The number of minutes the session should be in client preferences mode. Allowed values: 1 to 1440 minutes (24 hours).
p_check_interval in integer default c_check_interval_default , -- The number of seconds a session in logging mode looks for a changed configuration. Allowed values: 1 to 60 seconds.
p_call_stack in boolean default false , -- Should the call stack be included.
p_user_env in boolean default false , -- Should the user environment be included.
p_apex_env in boolean default false , -- Should the APEX environment be included.
p_cgi_env in boolean default false , -- Should the CGI environment be included.
p_console_env in boolean default false -- Should the console environment be included.
);
Exit/unset the preferences for a specific session/client_identifier.
If you exit/unset your own client preferencs then this has an immediate effect as we can unset the preferences in our package state. If you exit another session/client_identifier then it can take some seconds until the other session/client_identifier is reloading the configuration from the context (if available) or the client_prefs table. The default check interval for a changed configuration is ten seconds.
Exit/unset the preferences means also the cached log entries will be flushed to
the logging table CONSOLE_LOGS. If you do not need the cached entries you can
delete them in advance by calling the clear
procedure.
DO NOT USE THIS PROCEDURE IN YOUR BUSINESS LOGIC. IT IS INTENDED ONLY FOR MANAGING CLIENT PREFERENCES.
SIGNATURE
procedure exit (
p_client_identifier in varchar2 default my_client_identifier -- The client identifier provided by the application or console itself.
);
Exit/unset all client preferences in one go.
EXAMPLE
exec console.exit_all;
SIGNATURE
procedure exit_all;
Returns the version information from the console package.
Inspired by Steven's Live SQL example
select console.version from dual;
SIGNATURE
function version return varchar2;
Generates parameter tracing code for you.
Writes to the server output - switch it on to see results. Input for parameter
p_program
will be uppercased and spaces will be replaced by underscores. The
default for parameter p_level
is 3 (info). These calls are all equivalent:
set serveroutput on
exec console.generate_param_trace('some api.do stuff');
exec console.generate_param_trace('Some_API.do_stuff', 3);
exec console.generate_param_trace('SOME_API.DO_STUFF', console.c_level_info);
begin
console.generate_param_trace(
p_program => 'SOME_API.DO_STUFF',
p_level => console.c_level_info
);
end;
/
EXAMPLE 1
create or replace function demo_func (
p_01 in varchar2 ,
p_02 in number ,
p_03 in date )
return varchar2 is
begin
null; --YOUR CODE HERE
end demo_func;
/
set serveroutput on
exec console.generate_param_trace('demo func');
This will output something like:
--------------------------------------------------------
-- Signature not recoverable with user_arguments
-- We start with declare for easier formatting
-- Your Program : DEMO_FUNC
-- Package Name : -
-- Object Name : DEMO_FUNC
--------------------------------------------------------
declare
procedure console_add_in_params is
begin
console.add_param('p_01', p_01);
console.add_param('p_02', p_02);
console.add_param('p_03', p_03);
end console_add_in_params;
procedure console_add_out_params is
begin
console.add_param('your_return_value', your_return_value);
end console_add_out_params;
begin
console_add_in_params;
console.info('ENTER');
--------------------
-- YOUR CODE HERE
--------------------
console_add_out_params;
console.info('LEAVE');
----------------------
-- YOUR RETURN HERE
----------------------
exception
when others then
console_add_out_params;
console.error;
raise;
end;
/
As you can see in the procedure console_add_out_params
you have to align the
name of your return variable (console.add_param('your_return_value', your_return_value)
).
EXAMPLE 2
create or replace procedure demo_proc (
p_01 in varchar2 ,
p_02 in number ,
p_03 in date ,
p_04 in timestamp ,
p_05 in timestamp with time zone ,
p_06 in timestamp with local time zone ,
p_07 in interval year to month ,
p_08 in interval day to second ,
p_09 in boolean ,
p_10 in out clob ,
p_11 in out xmltype ,
p_12 in out console.t_client_prefs_row ,
p_13 in out console.t_client_prefs_tab )
is
begin
null; --YOUR CODE HERE
end demo_proc;
/
set serveroutput on
exec console.generate_param_trace('demo proc');
This will output something like:
--------------------------------------------------------
-- Signature not recoverable with user_arguments
-- We start with declare for easier formatting
-- Your Program : DEMO_PROC
-- Package Name : -
-- Object Name : DEMO_PROC
--------------------------------------------------------
declare
procedure console_add_in_params is
begin
console.add_param('p_01', p_01);
console.add_param('p_02', p_02);
console.add_param('p_03', p_03);
console.add_param('p_04', p_04);
console.add_param('p_05', p_05);
console.add_param('p_06', p_06);
console.add_param('p_07', p_07);
console.add_param('p_08', p_08);
console.add_param('p_09', p_09);
console.add_param('p_10', p_10);
console.add_param('p_11', p_11);
--unsupported data type PL/SQL RECORD: console.add_param('p_12', p_12);
--unsupported data type TABLE: console.add_param('p_13', p_13);
end console_add_in_params;
procedure console_add_out_params is
begin
console.add_param('p_10', p_10);
console.add_param('p_11', p_11);
--unsupported data type PL/SQL RECORD: console.add_param('p_12', p_12);
--unsupported data type TABLE: console.add_param('p_13', p_13);
end console_add_out_params;
begin
console_add_in_params;
console.info('ENTER');
--------------------
-- YOUR CODE HERE
--------------------
console_add_out_params;
console.info('LEAVE');
exception
when others then
console_add_out_params;
console.error;
raise;
end;
/
As you can see in the output, unsupported data types for console.add_param
will be commented out.
SIGNATURE
procedure generate_param_trace (
p_program in varchar2 , -- The package and/or program name ('some_api.do_stuff').
p_level in pls_integer default 3 -- The level you want to use for the parameter tracing.
);
Splits a string into a (pipelined) SQL table of varchar2.
If the separator is null the string will be splitted into its characters.
EXAMPLE
select * from console.split_to_table('1,2,3');
COLUMN_VALUE |
---|
1 |
2 |
3 |
SIGNATURE
function split_to_table (
p_string in varchar2 , -- The string to split into a table.
p_sep in varchar2 default ',' -- The separator.
) return t_vc2_tab pipelined;
Splits a string into a PL/SQL associative array.
If the separator is null the string will be splitted into its characters.
EXAMPLE
set serveroutput on
declare
v_array console.t_vc2_tab_i;
begin
v_array := console.split('A,B,C');
for i in 1 .. v_array.count loop
console.print(i||': '||v_array(i));
end loop;
end;
/
1: A
2: B
3: C
SIGNATURE
function split (
p_string in varchar2 , -- The string to split into an array.
p_sep in varchar2 default ',' -- The separator.
) return t_vc2_tab_i;
Joins a PL/SQL associative array into a string.
SIGNATURE
function join (
p_table in t_vc2_tab_i , -- The PL/SQL array to join into a string.
p_sep in varchar2 default ',' -- The separator.
) return varchar2;
Converts a boolean value to a string.
Returns Y
when the input is true, N
when the input is false and null when
the input is null.
SIGNATURE
function to_yn ( p_bool in boolean ) return varchar2;
Converts a boolean value to a string.
Returns true
when the input is true, false
when the input is false and null
when the input is null.
SIGNATURE
function to_string ( p_bool in boolean ) return varchar2;
Converts a string to a boolean value.
Returns true when the uppercased, trimmed input is TRUE
, Y
, YES
or 1
.
When the input is FALSE
, N
, NO
or 0
false is returned. In all other
cases null is returned.
SIGNATURE
function to_bool ( p_string in varchar2 ) return boolean;
Helper to convert a cursor to a HTML table.
Note: As this helper is designed to work always it does not check your log level. And if it would check, it would not help for the opening of the cursor, which is done before. To save work for your database in cases you are not in logging mode you should check the log level before open the cursor. Please see the examples below.
EXAMPLES 1 - Open cursor in advance
declare
v_dataset sys_refcursor;
begin
-- Your business logic here.
-- Debug code
if console.level_is_info then
open v_dataset for select * from user_tables;
console.info(console.to_html_table(v_dataset));
end if;
end;
/
EXAMPLES 2 - Open cursor in for loop
begin
-- Your business logic here.
-- Debug code
if console.my_log_level >= console.c_level_info then
for i in (
select console.to_html_table(cursor(select * from user_tables)) as html
from dual )
loop
console.info(i.html);
end loop;
end if;
end;
/
SIGNATURE
function to_html_table (
p_data_cursor in sys_refcursor ,
p_comment in varchar2 default null ,
p_include_row_num in boolean default true ,
p_max_rows in integer default 100 ,
p_max_column_length in integer default 1000 )
return clob;
Converts the given text to a Markdown code block by indent each line with four spaces.
SIGNATURE
function to_md_code_block (
p_text in varchar2 )
return varchar2;
Converts the given key and value strings to a Markdown table header.
to_md_tab_header
will return the following Markdown table header:
| Attribute | Value |
| ------------------------------ | ------------------------------------------- |
SIGNATURE
function to_md_tab_header (
p_key in varchar2 default 'Attribute' ,
p_value in varchar2 default 'Value' )
return varchar2;
Converts the given key and value strings to a Markdown table data row.
EXAMPLE
to_md_tab_header('CLIENT_IDENTIFIER', '{o,o} 4C8E71DF0001')
will return the
following Markdown table row:
| CLIENT_IDENTIFIER | {o,o} 4C8E71DF0001 |
SIGNATURE
function to_md_tab_data (
p_key in varchar2 ,
p_value in varchar2 ,
p_value_max_length in integer default 1000 ,
p_show_null_values in boolean default false )
return varchar2;
Returns a text bar consisting of unicode block characters.
You can build simple text based bar charts with it. Not all fonts implement clean block characters, so the result depends a little bit on the font. The unicode block characters can have eight different widths from 1/8 up to 8/8 - together with the default width of a bar chart of 25 characters you can show bar charts with a precision of 0.5 percent - that is not bad for a text based bar chart...
EXAMPLE
column textbar format a30
select 'Some text' as description, 0.84 as value, console.to_unibar(0.84) as textbar from dual union all
select 'Some other text' as description, 0.75 as value, console.to_unibar(0.75) as textbar from dual union all
select 'Bla bla bla' as description, 0.54 as value, console.to_unibar(0.54) as textbar from dual;
RESULT
DESCRIPTION VALUE TEXTBAR
--------------- ---------- ------------------------------
Some text .84 █████████████████████
Some other text .75 ██████████████████▊
Bla bla bla .54 █████████████▌
SIGNATURE
function to_unibar (
p_value in number ,
p_scale in number default 1 ,
p_width_block_characters in number default 25 ,
p_fill_scale in number default 0
) return varchar2 deterministic;
An alias for dbms_output.put_line.
Writing dbms_output.put_line is very annoying for me...
SIGNATURE
procedure print ( p_message in varchar2 );
A shorthand for
begin
console.print(console.format('A string with %s %s.', 'dynamic', 'content'));
--is equivalent to
console.printf('A string with %s %s.', 'dynamic', 'content');
end;
/
Also see console.format
SIGNATURE
procedure printf (
p_message in varchar2 ,
p0 in varchar2 default null ,
p1 in varchar2 default null ,
p2 in varchar2 default null ,
p3 in varchar2 default null ,
p4 in varchar2 default null ,
p5 in varchar2 default null ,
p6 in varchar2 default null ,
p7 in varchar2 default null ,
p8 in varchar2 default null ,
p9 in varchar2 default null );
Returns a string in the format hh24:mi:ss.ff6 (for example 00:00:01.123456).
Is internally used by the time_end
method and uses localtimestamp
to compare
with p_start
.
EXAMPLE
set serveroutput on
declare
v_start timestamp := localtimestamp;
begin
--do your stuff here
dbms_output.put_line('Runtime: ' || console.runtime(v_start));
end;
/
SIGNATURE
function runtime ( p_start in timestamp ) return varchar2;
Subtracts the start localtimestamp
from the current localtimestamp
and
returns the exracted seconds.
EXAMPLE
set serveroutput on
declare
v_start timestamp := localtimestamp;
begin
--do your stuff here
dbms_output.put_line (
'Runtime (seconds): ' || to_char(console.runtime_seconds(v_start)) );
end;
/
SIGNATURE
function runtime_seconds ( p_start in timestamp ) return number;
Subtracts the start localtimestamp
from the current localtimestamp
and
returns the exracted milliseconds.
EXAMPLE
set serveroutput on
declare
v_start timestamp := localtimestamp;
begin
--do your stuff here
dbms_output.put_line (
'Runtime (milliseconds): ' || to_char(console.runtime_milliseconds(v_start)) );
end;
/
SIGNATURE
function runtime_milliseconds ( p_start in timestamp ) return number;
Returns the level name for a given level id and null, if the level is not between 0 and 4.
SIGNATURE
function level_name (p_level in integer) return varchar2 deterministic;
Get the current scope (method, line number) from the call stack.
Is used internally by console to automatically provide the scope attribute for a log entry.
SIGNATURE
function scope return varchar2;
Get the current call stack (and error stack/backtrace, if available).
Is used internally by console to provide the call stack for a log entry when requested by one of the logging methods (which is the default for error and trace).
SIGNATURE
function call_stack return varchar2;
Get the current APEX environment.
Is used internally by console to provide the APEX environment for a log entry when requested by one of the logging methods.
SIGNATURE
function apex_env return clob;
Get the current CGI environment.
Is used internally by console to provide the CGI environment for a log entry when requested by one of the logging methods.
SIGNATURE
function cgi_env return varchar2;
Get the current user environment.
Is used internally by console to provide the user environment for a log entry when requested by one of the logging methods.
SIGNATURE
function user_env return varchar2;
Get the current console environment.
Is used internally by console to provide the console environment for a log entry when requested by one of the logging methods.
SIGNATURE
function console_env return varchar2;
High performance clob concatenation. Also see clob_flush_cache below.
Is used internally by console for the table method (and other things). Do not forget a final flush cache call when you use it in your own code.
EXAMPLE
set serveroutput on feedback off
declare
v_start timestamp := localtimestamp;
v_clob clob;
v_cache varchar2(32767 char);
begin
for i in 1..100000 loop
console.clob_append(v_clob, v_cache, 'a');
end loop;
console.clob_flush_cache(v_clob, v_cache);
dbms_output.put_line('Runtime (seconds): ' || to_char(console.runtime_seconds(v_start)));
dbms_output.put_line('Lenght CLOB : ' || length(v_clob));
end;
/
SIGNATURE
procedure clob_append (
p_clob in out nocopy clob ,
p_cache in out nocopy varchar2 ,
p_text in varchar2 );
High performance clob concatenation.
Overloaded method for appending a clob. Also see clob_append above with p_text beeing a varchar2 parameter and clob_flush_cache below.
SIGNATURE
procedure clob_append (
p_clob in out nocopy clob ,
p_cache in out nocopy varchar2 ,
p_text in clob );
Flushes finally the cache in a high performance clob concatenation.
Also see clob_append above.
SIGNATURE
procedure clob_flush_cache (
p_clob in out nocopy clob ,
p_cache in out nocopy varchar2 );
View the current package status (config, number entries cache/timer/counter, version etc.).
EXAMPLE
select * from console.status();
SIGNATURE
function status return t_attribute_value_tab pipelined;
View the global console configuration.
EXAMPLE
select * from console.conf();
SIGNATURE
function conf return t_attribute_value_tab pipelined;
View the client preferences.
EXAMPLE
select * from console.client_prefs();
SIGNATURE
function client_prefs return t_client_prefs_tab pipelined;
Deletes log entries for the given condition.
Deletion is only allowed for the owner of the package console.
EXAMPLES
--> default: all level info, debug and trace older than 30 days
exec console.purge;
--> all three examples are equivalent
exec console.purge(3, 0.25);
exec console.purge(console.c_level_info, 0.25);
exec console.purge(p_min_level => console.c_level_info, p_min_days => 0.25);
SIGNATURE
procedure purge (
p_min_level in integer default c_level_info, -- Delete log entries greater or equal the given level.
p_min_days in number default 30 ); -- Delete log entries older than the given minimum days.
Deletes all log entries except level permanent.
Deletion is only allowed for the owner of the package console.
EXAMPLE
exec console.purge_all;
SIGNATURE
procedure purge_all;
Creates a cleanup job which deletes old log entries from console_logs and stale debug sessions from console_client_prefs.
SIGNATURE
procedure purge_job_create (
p_repeat_interval in varchar2 default 'FREQ=DAILY;BYHOUR=1;' , -- See the Oracle docs: https://docs.oracle.com/en/database/oracle/oracle-database/19/admin/scheduling-jobs-with-oracle-scheduler.html#GUID-10B1E444-8330-4EC9-85F8-9428D749F7D5
p_min_level in integer default c_level_info , -- Delete log entries greater or equal the given level.
p_min_days in number default 30 -- Delete log entries older than the given minimum days.
);
Drops the cleanup job (if it exists).
SIGNATURE
procedure purge_job_drop;
Enables the cleanup job (if it exists).
SIGNATURE
procedure purge_job_enable;
Disables the cleanup job (if it exists).
SIGNATURE
procedure purge_job_disable;
Runs the cleanup job (if it exists).
SIGNATURE
procedure purge_job_run;