Configuring the logfiles

In this recipe, we will discuss the configuration of the logfiles. The configuration of the logfiles is important because it enables us to fine-tune the information we want to gather from the BPEL process execution.

Getting ready

For this recipe, there is no special preparation needed. However, further discussion will lead us to more specific configuration of the logfiles. For that purpose, we will use the BPEL process that we prepared for this chapter. The BPEL process first checks the hotel availability, receives the room price, and checks for car availability.

How to do it…

By following the next steps, we will configure logfiles through the Oracle Enterprise Manager Console:

  1. Log in to the Oracle Enterprise Manager Console.
  2. Select soa-infra from the tree on the left side. Then, right-click on soa-infra and select Logs | Log Configuration.
    How to do it…
  3. The Log Configuration opens and you have two tabs to choose. The Log Levels tab is used for changing the level of tracing that we use for a particular logger. At the moment, we are more interested in the Log Files tab. We will create a new logfile for the logging. Thus, we select odl-handler and click on the Create Like… button:
    How to do it…
  4. In the Create Log File window, enter the following fields:
    • Log file
    • Log Path
    • Loggers to Associate

Now we have defined the logger file in order to separate logging for our custom logger defined in the Creating a custom logger in a BPEL process recipe.

How it works…

Oracle SOA Suite has its logging configuration managed through the Oracle Enterprise Manager Console. There exist the following four predefined logfiles for the Oracle SOA Suite components:

  • em-log-handler (logs the enterprise manager data)
  • em-trc-handler (logs the enterprise manager data)
  • odl-handler (logs the general diagnostic data)
  • owsm-message-handler (logs diagnostic data for the Oracle Web Service Manager)

Tip

By defining the logfile, there is no logging enabled yet. To enable logging, we must configure that through the loggers in the Log Levels tab. We will cover this in our next recipe, Changing the level of tracing.

There's more…

In a BPEL process, there is also a possibility to configure the logfiles autonomously from the Oracle SOA Suite. We will utilize the sample BPEL process we prepared in previous recipes with the LOG4J logging utility. Our task is to make every BPEL process instance log into its own logfile. The format of the logfile name is log_BPEL_<instance_id>.log:

  1. In the JDeveloper project, we add the LOG4J library into the SCA-INF/lib directory.
  2. Additionally, create the LOG4J properties file. Place the properties file into the SOA domain server root location <domain_home>. The content of the LOG4J properties file we defined is as shown in the following code:
    log4j.rootLogger=debug, stdout, BPEL
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    # Pattern to output the caller's file name and line number.
    log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
    log4j.appender.BPEL=org.apache.log4j.RollingFileAppender
    log4j.appender.BPEL.File=example.log
    log4j.appender.BPEL.MaxFileSize=100KB
    log4j.appender.BPEL.MaxBackupIndex=5
    log4j.appender.BPEL.layout=org.apache.log4j.PatternLayout
    log4j.appender.BPEL.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n

That's it! We prepared the infrastructure to utilize the custom logfile defined outside of the Oracle SOA Suite framework.

Creating a log for every BPEL instance run

We will now create the Logger class which will use the infrastructure we just prepared:

  1. In JDeveloper, we define a new class and name it LogDynamic. In the static section, we set the properties file for logging and extract FileAppender from the logging configuration as shown in the following code:
    static {
      String sLog4jFile = "C:\Programs\Oracle\Middleware\user_projects\domains\SOA_Dev\dyna_log4j.properties";
      PropertyConfigurator.configure(sLog4jFile);
      Logger rootLogger= Logger.getRootLogger();
      Enumeration appenders = rootLogger.getAllAppenders();
      while(appenders.hasMoreElements()) {
        Appender currAppender = (Appender) appenders.nextElement();
        if(currAppender instanceof FileAppender) {
          fa = (FileAppender) currAppender;
        }
      }
    }
  2. In the log procedure, first set the filename for the logging if it is not already set as shown in the following code:
      if (fa!= null) {
        if(fa.getFile().indexOf(pid) == -1)
        {
          fa.setFile("C:/temp/log_BPEL_" + pid + ".log");
          fa.activateOptions(); 
        }
      }
  3. Next, we perform the actual logging:
    logger.log(Level.INFO, message);
  4. In the BPEL process, use the Java Embedding activity to call the logging method as shown in the following code:
    <extensionActivity>
      <bpelx:exec name="Java_Log_JUL_LOG4J" language="java">
        <![CDATA[
          org.packt.log.LogDynamic.log("Hello from Log4J process with id: " + getInstanceId(), ""+ getInstanceId());        
        ]]>
      </bpelx:exec>
    </extensionActivity>

See also

In the next three recipes, we will discuss Changing the level of tracing, Editing the logfiles, and Viewing logfiles in the Enterprise Manager Console.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset