This article is part of a series about the upcoming release of Logger 3.0.0. A full list of these posts can be found here.
Plugins support is by far the biggest feature added in the 3.0.0 release. It allows you to call a custom procedure for each log type after an entry has been written to the log table.
Why would you want to have a plugin for Logger? Suppose that each time an error occurs you want to automatically create a support ticket in your corporate issue tracking system. There was no clean and supported way of doing this before plugins. Now with plugins, you can create a custom function that will automatically create a ticket each time
logger.log_error is called.
Here's an example of how to create the custom plugin procedure, register it, and run it:
Step 1 - Create plugin procedure:
create or replace procedure log_test_plugin( p_rec in logger.rec_logger_log) as l_text logger_logs.text%type; begin dbms_output.put_line('In Plugin'); dbms_output.put_line('p_rec.id: ' || p_rec.id); select text into l_text from logger_logs_5_min where id = p_rec.id; -- Create issue tracking ticket here dbms_output.put_line('Text: ' || l_text); end; /
Step2 - Register plugin and configure Logger:
-- Register new plugin procedure for errors update logger_prefs set pref_value = 'log_test_plugin' where pref_name = 'PLUGIN_FN_ERROR'; -- Configure with Logger exec logger_configure;
Step 3 - Run code:
set serveroutput on exec logger.log_error('hello'); In Plugin p_rec.id: 811 Text: hello
As you can see, each time you call
logger.log_error the new plugin procedure (
log_test_plugin) is run. In this example the plugin procedure just output some text messages but it can do whatever you want it to do.
You can also run standard
logger.log_<fn> commands in your plugin code. The catch is that if Logger is already executing a plugin for the given level it will not re-run the plugin. This helps prevent recusion/infinite loops.
To keep things simple for now, Logger only supports plugins for
logger.log_error. As time goes on we will expand the plugin support for the other types of logging.
The complete plugins documentation can be found here