Finding value of LOG_ROOT from within Websphere application - Websphere

This is a discussion on Finding value of LOG_ROOT from within Websphere application - Websphere ; Hi there. I've tried several searches for Google but can not seem to find an answer to my question. I simply want to know how to get the location of the standard log directory for my profile/server within a Servlet/JSP/Struts ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Finding value of LOG_ROOT from within Websphere application

  1. Finding value of LOG_ROOT from within Websphere application

    Hi there. I've tried several searches for Google but can not seem to find an answer to my question. I simply want to know how to get the location of the standard log directory for my profile/server within a Servlet/JSP/Struts application. In the WebSphere admin console, I've noticed this variable is called LOG_ROOT. I've tried to simply use System.getenv("LOG_ROOT"); but that throws an exception.

    Is there a simply way using the com.ibm.websphere API to get this path?

    Thanks

  2. Re: Finding value of LOG_ROOT from within Websphere application

    Hi,

    In the console, look under Environment -> WebSphere Variables.

    Brian

  3. Re: Finding value of LOG_ROOT from within Websphere application

    I don't know if I'd call it simple, but try this code. Call
    getAppServerVariable() to get whatever variable you want to retrieve. I
    assume you have used the AdminClient or AdminService before.

    private static final int SCOPE_SERVER = 1;
    private static final int SCOPE_NODE = 2;
    private static final int SCOPE_CELL = 3;

    public String getAppServerVariable(String variableName, int scope)
    throws Exception
    {
    String value = null;
    ConfigService cs = getConfigService();

    Session session = new Session();
    try
    {
    String containmentPath = getContainmentPathByScope(scope);
    if(containmentPath==null)
    throw new Exception("bad scope");

    ObjectName[] onCell = cs.resolve(session, containmentPath);
    ObjectName uron = new ObjectName("WebSphere:" +
    SystemAttributes._WEBSPHERE_CONFIG_DATA_TYPE
    + "=VariableSubstitutionEntry");
    for (int i = 0; i < onCell.length; i++)
    {
    ObjectName[] configObjects = cs.queryConfigObjects(session,
    onCell[i], uron, null);

    for (int j = 0; j < configObjects.length; j++)
    {
    AttributeList currentAttributes =
    cs.getAttributes(session, configObjects[j], null, false);
    String symbolicName = (String)
    ConfigServiceHelper.getAttributeValue(
    currentAttributes,
    "symbolicName");
    if(symbolicName.equals(variableName))
    {
    value = (String)
    ConfigServiceHelper.getAttributeValue(currentAttri butes, "value");
    break;
    }
    }
    if(value!=null) break;
    }

    if(value==null)
    throw new Exception("value not found");

    cs.discard(session);
    }
    catch (Exception e)
    {
    throw e;
    }
    return value;
    }

    private String getServerContainmentPath()
    {
    String cell = getServerMBeanProperty("cell");
    String node = getServerMBeanProperty("node");
    String process= getServerMBeanProperty("process");

    StringBuffer containmentPath = new StringBuffer();
    containmentPath.append("Cell=").append(cell);
    containmentPath.append(":Node=").append(node);
    containmentPath.append(":Server=").append(process);

    return containmentPath.toString();
    }

    private String getNodeContainmentPath()
    {
    String cell = getServerMBeanProperty("cell");
    String node = getServerMBeanProperty("node");

    StringBuffer containmentPath = new StringBuffer();
    containmentPath.append("Cell=").append(cell);
    containmentPath.append(":Node=").append(node);

    return containmentPath.toString();
    }

    private String getCellContainmentPath()
    {
    String cell = getServerMBeanProperty("cell");
    StringBuffer containmentPath = new StringBuffer();
    containmentPath.append("Cell=").append(cell);
    return containmentPath.toString();
    }

    private String getContainmentPathByScope(int scope)
    {
    String cp = null;
    if(scope==SCOPE_CELL)
    cp = getCellContainmentPath();
    if(scope==SCOPE_NODE)
    cp = getNodeContainmentPath();
    if(scope==SCOPE_SERVER)
    cp = getServerContainmentPath();
    return cp;
    }

    private String getServerMBeanProperty(String name)
    {
    String value = null;
    try
    {
    // Here you need the WAS AdminClient or AdminService
    ObjectName objectName = _adminClient.getServerMBean();
    // ObjectName objectName = _adminService.getLocalServer();
    value = objectName.getKeyProperty(name);
    }
    catch (Exception e)
    {
    System.err.println("error during getServerMBeanProperty");
    }
    return value;
    }


    wrote in message
    news:1298219762.1185915101294.JavaMail.wassrvr@lts gwas009.sby.ibm.com...
    > Hi there. I've tried several searches for Google but can not seem to find
    > an answer to my question. I simply want to know how to get the location of
    > the standard log directory for my profile/server within a
    > Servlet/JSP/Struts application. In the WebSphere admin console, I've
    > noticed this variable is called LOG_ROOT. I've tried to simply use
    > System.getenv("LOG_ROOT"); but that throws an exception.
    >
    > Is there a simply way using the com.ibm.websphere API to get this path?
    >
    > Thanks




  4. Re: Finding value of LOG_ROOT from within Websphere application

    Hi Tom

    I have the same need as the submitter of the original message ? getting the location of the standard log directory for my profile/server within a Servlet/SOAP application. I prefer not to use WAS environment variables or configuration file fields because the application is hosted in the production environment by an external team ? this could add a new variable in production problem determination. I use a WebSphere Application Server V5.1.1 with Cumulative Fix 13, running under AIX operating system.

    I tried to run your code but I always get null from the CONFIGSERVICEFACTORY.GETCONFIGSERVICE() call. I found out from the IBM Software Group pages that there is a bug in this API, described at APAR #PK31314 (http://www-1.ibm.com/support/docview...id=swg1PK31314). In the same page it is said that the fix is available within WAS V5.1.1 Cumulative Fix 13.

    I took our development WAS server up to V5.1.1.13 in order to apply the fix. Then I ran the code again and got exactly the same null value.

    Are you aware of any other dependency for solving this known bug in the WAS administrative classes ? When you run this code snippet successfully, which WAS version do you use (and also what SO you run WAS under) ?

    Any help in this matter will be appreciated,
    Marcelo Ito
    mito@br.ibm.com


  5. Re: Finding value of LOG_ROOT from within Websphere application

    Hi

    For whom it may concern, Mark Lewis posted a reply to this post in the developerWorks WAS forum (http://www-128.ibm.com/developerwork...m=266#13985866) that worked just perfectly for me. I am not getting a null ConfigService object anymore.

    "Hi Marcelo,

    You may need to use the following to get hold of the config service if
    not running on a standalone server:

    ConfigService configService = ConfigServiceFactory.getConfigService();
    if (configService == null)
    {
    Properties p = new Properties();
    p.setProperty("location", "local");
    configService = ConfigServiceFactory.createConfigService(true, p);
    }

    Hope that helps,

    Mark."


+ Reply to Thread