Forum Stats

  • 3,851,536 Users
  • 2,263,995 Discussions
  • 7,904,771 Comments

Discussions

logging in SOA 12c

vikas.singh
vikas.singh Member Posts: 18 Blue Ribbon
edited Sep 11, 2020 10:27AM in SOA Suite Discusssions

Hi,

Is there a way to generate logs e.g. soa.log file in Oracle SOA 12.2.1.3.0? Please share some details so I can print invoke level input and output variables to soa.log file.

Regards,

Vikas Kumar

Answers

  • vikas.singh
    vikas.singh Member Posts: 18 Blue Ribbon
    edited Aug 6, 2020 12:43AM

    Hello Friends,

    Can anyone of you please help me with Custom logging in SOA 12c?

    Regards,

    Vikas

  • Martin.sv
    Martin.sv Member Posts: 11
    edited Aug 7, 2020 1:17AM

    Hi,

    Have you tried Log4j with BPEL? That could be a good way to log input/output variable for debugging. Maybe a Java embedding activity with something like this:

    Logger mLogger = Logger.getLogger("myLog"); 

    mLogger.info(" >>>>>>>>>  log4j statement ****************"); 

    mLogger.debug(">>>>>>>>>>>>>>>Logger Debug statement"); 

    mLogger.error(">>>>>>>>>>>>>>>Logger Error");

    java.lang.String ErrorTrace = ((org.w3c.dom.Element)getVariableData("inputVariable","payload","/client:process/client:input")).getFirstChild().getNodeValue();

    mLogger.info("error trace ::::"+ErrorTrace);

    mLogger.info(ErrorTrace);

    Please also, check documentation related to log files and diagnostic data.

    https://docs.oracle.com/middleware/1213/core/ASADM/logs.htm#ASADM217

    Regards.

    Martin.

  • vikas.singh
    vikas.singh Member Posts: 18 Blue Ribbon
    edited Sep 4, 2020 3:30PM

    Hi Martin,

    Thanks for your reply. Do I need to add any jar file in classpath or any other settings required other than java embed code in bpel.

    Thanks!!

    Regards,

    Vikas

  • Martien van den Akker
    Martien van den Akker Member Posts: 2,777 Bronze Crown
    edited Sep 11, 2020 10:27AM

    Hi Vikas,

    Although @Martin provided a perfectly sensible solution, I'd like to show how I did it. I didn't need to add or configure Log4J. The following just works in a straightforward SOASuite.

    First I created a class like this:

    /*** @author Martien van den Akker, Darwin-IT Professionals* @version 1.0** Wrapper class around logging mechanism to get confined and easy log methods.** History* 2019-01-19 - 1.0 - Initial Creation*/package nl.darwin-it.soautils.logging;import java.util.logging.Level;import java.util.logging.Logger;public class Log {    private static Logger log;    private String className;    private boolean toConsole = false;    /**     * Only log to console if toConsole is true, unless override is true     * @param logText     * @param override     */    private void pl(String logText, boolean override) {        if (toConsole || override) {            System.out.println(logText);        }    }    /**     * Only log to console if toConsole is true;     * @param logText     */    private void pl(String logText) {        pl(logText, false);    }    public Log(Class<?> loggingClass) {        super();        setClassName(loggingClass.getName());        log = Logger.getLogger(getClassName());    }       public Log(String loggingClass) {        super();        setClassName(loggingClass);        log = Logger.getLogger(getClassName());    }    private String getText(String methodName, String text) {        return className + "." + methodName + ": " + text;    }    public void debug(String methodName, String text) {        String logText = getText(methodName, text);        pl(logText);        log.fine(logText);    }    public void trace(String methodName, String text) {        String logText = getText(methodName, text);        log.finest(logText);    }    public void info(String methodName, String text) {        String logText = getText(methodName, text);        pl(logText);        log.info(logText);    }    public void warn(String methodName, String text) {        String logText = getText(methodName, text);        pl(logText);        log.warning(logText);    }    public void warn(String methodName, String text, Exception e) {        String logText = getText(methodName, text);        pl(logText, true);        pl("Error Message: " + e.getMessage());        pl("Error Caused by: " + e.getCause());        log.log(Level.WARNING, logText, e);    }    public void error(String methodName, String text) {        String logText = getText(methodName, text);        pl(logText, true);        log.severe(logText);    }    public void error(String methodName, String text, Exception e) {        String logText = getText(methodName, text);        pl(logText, true);        pl("Error Message: " + e.getMessage());        pl("Error Caused by: " + e.getCause());        log.log(Level.SEVERE, logText, e);    }    public void start(String methodName) {        trace(methodName, "Start");    }    public void end(String methodName) {        trace(methodName, "End");    }    public final void setToConsole(boolean toConsole) {        this.toConsole = toConsole;    }    public final boolean isToConsole() {        return toConsole;    }    public final void setClassName(String className) {        this.className = className;    }    public final String getClassName() {        return className;    }}

    Pretty straight forward en just a few helper methods. I packaged this in a jar file and added it to the SCA_INF/lib folder of my composite.

    Then I created an embedded subproces like this (you could also create it like a reusable proces if you want to use it within multiple bpels in your composite):

    pastedImage_3.png

    You see that the main scope of the embedded process has four variables: compositeName, componentName, methodName and text. All defined as String. These function as parameters.

    The Log activity is an Embedded Java that looks like:

    String compositeName = (String) getVariableData("compositeName");  String componentName = (String) getVariableData("componentName");  String text = (String) getVariableData("text");  String methodName= (String) getVariableData("methodName");  Log log = new Log(compositeName+"."+componentName);   String message="**** BPEL "+methodName +" " + text +" ****";    log.info(methodName, message);    addAuditTrailEntry(message);

    (Sorry for the layout, couldn't get to the advanced editor, since my javascript blocker is a bit nasty today.)

    In BPEL you need to add an Import like this:

      <import location="nl.minvenj.ind.soautils.logging.Log" importType="http://schemas.oracle.com/bpel/extension/java"/>

    Doing this in an embedded/reusable subprocess pays of when you want to do multiple loggings. Now I only need to add a call activity like this:

    pastedImage_9.png

    I also have an embedded subprocess for errors, LogError, to be used in fault handlers.

    An logged error in the Diagnostics.xml looks like:

     <attr name='APP' value='soa-infra'/> <attr name='partition-name' value='DOMAIN'/> <attr name='tenant-name' value='GLOBAL'/> <attr name='oracle.soa.tracking.FlowId' value='600130'/> <attr name='oracle.soa.tracking.InstanceId' value='1070624'/> <attr name='oracle.soa.tracking.SCAEntityId' value='500073'/> <attr name='FlowId' value='0000NHsg0DI5aaC5rFK6yY1VLnaO00002d'/> <txt>oracle.bpel.BerichtVerdeler.BerichtVerdelerProcess.LogBerichtVerwerkingGefaald: **** BPEL LogBerichtVerwerkingGefaald Verwerking van bericht with berichtType: AapNootMies gefaald!  ****</txt></msg>

    Kind regards,

    Martien