Skip to content

Writing an Appender

Andres Gomez Casanova edited this page Jun 3, 2022 · 2 revisions

Description

These are the steps to add your own appender into the utility.

  1. Create the stored procedure for the appender.
  2. Change the configuration to declare the appender
  3. Use it.

Stored Procedure

You should create a stored procedure that will be called from the LOG stored procedure. Let's suppose it is called LOG_MY_APPENDER. It will have the following IN parameters in this order:

  • LOGGER_ID ANCHOR LOGDATA.CONF_LOGGERS.LOGGER_ID (SMALLINT)
  • LEVEL_ID ANCHOR LOGDATA.LEVELS.LEVEL_ID (SMALLINT)
  • MESSAGE ANCHOR LOGDATA.LOGS.MESSAGE (VARCHAR(512))
  • CONFIGURATION ANCHOR LOGDATA.CONF_APPENDERS.CONFIGURATION (XML)

Here, is an example:

/**
 * Description of Log My Appender
 *
 * IN LOGGER_ID
 *   Identification of the associated logger.
 * IN LEVEL_ID
 *   Identification of the associated level.
 * IN MESSAGE
 *   Descriptive message to write in the log table.
 * IN CONFIGURATION
 *   Any particular configuration for the appender. 
 */
ALTER MODULE LOGGER PUBLISH
  PROCEDURE LOG_MY_APPENDER (
  IN LOGGER_ID ANCHOR LOGDATA.CONF_LOGGERS.LOGGER_ID,
  IN LEVEL_ID ANCHOR LOGDATA.LEVELS.LEVEL_ID,
  IN MESSAGE ANCHOR LOGDATA.LOGS.MESSAGE,
  IN CONFIGURATION ANCHOR LOGDATA.CONF_APPENDERS.CONFIGURATION
  )
  LANGUAGE SQL
  SPECIFIC P_MY_APPENDER
  DYNAMIC RESULT SETS 0
  MODIFIES SQL DATA
  NOT DETERMINISTIC
  NO EXTERNAL ACTION
  PARAMETER CCSID UNICODE
 P_MY_APPENDER: BEGIN
  -- Body of My Appender.
 END P_MY_APPENDER @

It is recommended to create this stored procedure with the option PUBLISH, in this way you can test its behavior without using the utility.

This stored procedure cannot be marked as autonomous because there is a restriction to creating Autonomous procedures with XML parameters: Create procedure (Autonomous routine restrictions).

Included in the tables

Once it is integrated, you should change the configuration to indicate the utility to use your appender.

INSERT INTO LOGDATA.APPENDER (APPENDER_ID, NAME)
  VALUES (6, 'MY_APPENDER');

The name is very important, because it should match the second part of the name of the stored procedure. The prefix name for appenders is LOG_, and the suffix is the name in this table, in this case MY_APPENDER. And the utility will call LOG_MY_APPENDER.

Configure your own appender:

INSERT INTO LOGDATA.CONF_APPENDERS (NAME, APPENDER_ID, CONFIGURATION, PATTERN)
  VALUES ('My Appender configuration', 6, NULL, '%p: %c => %m');

Associate a logger with your appender:

INSERT INTO REFERENCES (LOGGER_ID, APPENDER_REF_ID)
  VALUES (0, 2);

Using new appender

Now you are ready to use your appender!

CALL LOG_MY_APPENDER(0, -1, 'Message test 1', NULL);

CALL LOGGER.LOG(0, -1, 'Message test 2');
Clone this wiki locally