How to use log4j for a axis2 webservice

Posted by KItis on Stack Overflow See other posts from Stack Overflow or by KItis
Published on 2010-05-28T11:07:17Z Indexed on 2010/05/28 11:11 UTC
Read the original article Hit count: 313

Filed under:
|
|
|
|

I have created a simple axis2 webservice to understand logging functionality in a webservice. in this sample webservice, when a client calls this webservice, first it reads the log4j.property file. then i can see the logs being printed on console. but i have included file appender too into the property file. but i can not file the log file any where in my sample webapplication. i am using tomcat to run the webservice. following is webservice interface method called by client.

package test;

import java.io.IOException; import java.io.InputStream; import java.util.Properties;

import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator;

public class WSInterface {

static final Logger logger = Logger.getLogger(WSInterface.class);

public String log4jTest(String input){

    InputStream inputStream = this.getClass().getClassLoader()  
                     .getResourceAsStream(input);  

    Properties properties = new Properties();  

    System.out.println("InputStream is: " + inputStream);  

    //load the inputStream using the Properties  
    try {
        properties.load(inputStream);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    PropertyConfigurator.configure(properties);
    logger.debug("Hello World!");


    Class myclass = WSInterface.class;
    String url =  myclass.getResource("WSInterface.class").toString();   

    String output = "";
    return url;
}

}

© Stack Overflow or respective owner

Related posts about web-services

Related posts about logging