Friday, March 21, 2014

Setup Oracle Diagnostic Logging (ODL) for OIM Plug-ins

Version: Oracle Identity Manager 11g
Description: Oracle Diagnostic Logging (ODL) is the principal logging service used by OIM. This post shows you how to setup ODL for your OIM plug-ins (Event Handlers, Schedule Task, and Adapter code).

1. Include ojdl.jar, which is located in "$MW_HOME/oracle_common/modules/oracle.odl_11.1.1" directory, to your project classpath.

2. Setup the ODLLogger in your Java application. An example is given below.

package oim.example.adapters;

import java.util.logging.Level;
import java.util.logging.Logger;
import oracle.core.ojdl.logging.ODLLogger;

public class PrintOldAndValues 
{
    //Setup ODLLogger; Each log will have the fully qualified class name 
    private static final Logger logger = ODLLogger.getLogger(PrintOldAndValues.class.getName());

    /**
     * Print out old and new values of a process
     * form field after a change has been made.
     * @param   oldValue    Previous value on process form attribute
     * @param   newValue    Modified value on process form attribute
     */
    public static void printOldAndNewValues(String oldValue, String newValue)
    {
        //Print out logs
        logger.log(Level.INFO, "Executing printOldAndNewValues() V1.0");
        logger.log(Level.INFO, "Previous Value: {0}", oldValue);
        logger.log(Level.INFO, "New Value: {0}", newValue);
    }
}

3. Modify the logging.xml file, which is located in "$MW_HOME/user_projects/domains/$DOMAIN_NAME/config/fmwconfig/servers/oim_server1" directory, to include the following:
  • Inside the log_handlers tag define your handler. You can specify any name for your log handler. An example is given below with the log handler named test and the log file location as "$MW_HOME/user_projects/domains/$DOMAIN_NAME/servers/oim_server1/logs/test.log".

     <log_handler name='test' level='TRACE:32' class='oracle.core.ojdl.logging.ODLHandlerFactory'>
       <property name='path' value='${domain.home}/servers/${weblogic.Name}/logs/test.log'/>
       <property name='useThreadName' value='true'/>
       <property name='maxFileSize' value='5242880'/>
       <property name='maxLogSize' value='52428800'/>
       <property name='encoding' value='UTF-8'/>
     </log_handler>
  • Inside the loggers tag define your custom logger. You must specify the fully qualified classname as the name of the logger. Also, a log handler must be specified. An example is given below which uses the fully qualified class name in the sample code given in step 2 and the log handler mentioned above.

     <logger name="oim.example.adapters.PrintOldAndValues" level="TRACE:32" useParentHandlers="false">
        <handler name="test"/>
     </logger>


1 comment:

  1. I have been reading your blogs.You explain them in a very simple manner. Thanks for various posts.
    One small correction in the above post.
    "Inside the loggers tag define your custom logger. You must specify the fully qualified classname as the name of the logger.". This statement is wrong.

    For example, instead of mentioning class name inside "getLogger" method, you can specify a generic message like below:

    private static final Logger logger = ODLLogger.getLogger("CUSTOM.ABC.EVENTHANDLERS");

    This "CUSTOM.ABC.EVENTHANDLERS" must be used inside logger tags as logger name. By following this approach, you can set same log level for all event handlers and redirect them to a same log file. Similarly you can have "CUSTOM.ABC.SCHEDULERS" for all the scheduled tasks.

    Hope this helps others!!!

    ReplyDelete