Search code examples
javaweblogicwlst

Using displayLogs() in WLSTInterpreter NameError: displayLogs


I am attempting to get a log output from the displayLogs() command and I have trying to do this within the WLST Interpreter. I get the following error which is "NameError: displayLogs" I am able to perform other commands such as domainRuntime() and a number of others, but this one seems to be outside the realm. Do I need to run it with some sort of classes in the classpath when running it? Any help would be appreciated.

The source code that I am using below:

package wlst;
import weblogic.management.scripting.utils.WLSTInterpreter;
import org.python.util.InteractiveInterpreter;
import org.python.core.PyObject;

public class EmbeddedWLST
{
  static InteractiveInterpreter interpreter = null;
  EmbeddedWLST() {
    interpreter = new WLSTInterpreter();
  }

private static void connect() {
    StringBuffer buffer = new StringBuffer();
    buffer.append("connect('USERNAME','PASSWORD','t3://HOSTANAME:PORT')");
    interpreter.exec(buffer.toString());
}

public static void main(String[] args) {
    new EmbeddedWLST();
    connect();
    PyObject cmo = interpreter.get("cmo");
    String command = getLogs();
    System.out.println("Executing Get Logs");
    interpreter.exec(command);
    System.out.println("Getting Output Object");
    PyObject output = interpreter.get("output");
    System.out.println(output.getClass());
    System.out.println(output);
  }

    private static String getLogs() {
        StringBuffer buf = new StringBuffer();
        buf.append( "output = displayLogs(returnData=1)\n" );
        return buf.toString();
    }
}

Solution

  • UPDATE


    Everything you are looking for lives in:

    <install dir>/oracle_common/common/wlst
    

    A simple grep -R displayLogs * returned the python module you need:

    <install dir>/oracle_common/common/wlst/oracle-logging.py
    

    You will need to include the jars that script needs on your classpath, specifically the logging jar ojdl.jar found under <install dir>/oracle_common/modules/oracle.odl

    The above information was found by comparing the scripts below (I am using 10.3.6):


    This script <install dir>/wlserver_10.3/common/bin/wlst.sh fails with:

    wls:/offline> listLogs()
    Traceback (innermost last):
      File "<console>", line 1, in ?
    NameError: listLogs
    

    This script <install dir>/oracle_common/common/bin/wlst.sh succeeds (and has many more options than the script above) :

    wls:/offline> listLogs()
    Not connected to a Weblogic server. Connect to a Weblogic server first.
    

    Make sure you have all the same jars and properties set as the second script does.