Hello Xu,

Here is an example of how I used log4j logging in a WSRF service. Not sure if this is exactly the best way, but FWIW it worked for me. In my case there are three Java classes that I particularly cared about logging: Scheduler, ResourceManagerImpl, and MessageConsumer. For purposes of this example I'll just show you the code for the MessageConsumer class, as that is a tiny (very!) and easy to follow class.


-----------------------------------------
These are all the non-comment lines in my
container-log4j.properties file:
-----------------------------------------
[EMAIL PROTECTED] ~]$ grep -v "#" $GLOBUS_LOCATION/container-log4j.properties

log4j.rootCategory=ERROR, A1


log4j.appender.A1=org.apache.log4j.ConsoleAppender

log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d{ISO8601} %-5p %c{2} [%t,%M:%L] %m%n

log4j.category.org.globus=INFO


log4j.category.glambda.nrm.reservation.rm.Scheduler=DEBUG
log4j.category.glambda.nrm.reservation.rm.ResourceManagerImpl=DEBUG
log4j.category.glambda.nrm.reservation.util.MessageConsumer=DEBUG



------------------------------------
Here is my MessageConsumer.java file:
------------------------------------
[EMAIL PROTECTED] src]$ cat glambda/nrm/reservation/util/MessageConsumer.java

package glambda.nrm.reservation.util;

import edu.lsu.cct.cosched.clientAPI.Notifiable;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class MessageConsumer implements Notifiable {

    private static Log logger = LogFactory.getLog(MessageConsumer.class);

    public void newMessage(java.lang.String message) {
        logger.info("Received HARC Notification \"" + message + "\"");
    }
}


------------------------------------------
Here is an example log message output line,
from the Globus container:
------------------------------------------
2007-09-17 17:14:43,929 INFO util.MessageConsumer [Thread-43,newMessage:12] Received HARC Notification "0: Result stored: ActionsSucceeded"



Note, I never called org.apache.log4j.PropertyConfigurator.configure() -- maybe you could try taking that out and see what happens.

Hope my example is helpful to you, have fun!


Steve

Xu Xiao wrote:
hi,

  I wrote a globus wsrf service in my project. When I tested it, I met
a logging problem.
  I used $GLOBUS_LOCATION/log4j.properties as my log4j file, and its content:

# Set root category priority to WARN and its only appender to A1.
log4j.rootCategory=INFO, A1
# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d{ISO8601} %-5p %c{2}
[%t,%M:%L] %m%n
# Display any warnings generated by our code
log4j.category.org.globus=WARN
# added by me
log4j.category.hit.pact.crawler.common.Globals=INFO
# added by me
log4j.category.pact.grid=INFO
# Enable SOAP Message Logging
# log4j.category.org.globus.wsrf.handlers.MessageLoggingHandler=DEBUG
# Comment out the line below if you want to log every authorization
# decision the notification consumer makes.
log4j.category.org.globus.wsrf.impl.security.authorization.ServiceAuthorizationChain=WARN

I am using GDT and my service code is like:

public class MyService {

     static {
           System.out.println("this is a test.");
           Globals.logger.info("hello");
           <several important initializing operations>
     }

      @GridMethod public String submit(String input){...};

}

the logging code is in the static block, so it will be called only
when a client calls the service for the first time.

and this is the implementation of class Globals:

package hit.pact.crawler.common;
public class Globals {
      public static final Log logger = LogFactory.getLog(Globals.class);
}

also I had another implementation of Globals which is like:

package hit.pact.crawler.common;
public class Globals {
      public static Logger logger = Logger.getLogger(Globals.class.getName());
      static {
                org.apache.log4j.PropertyConfigurator.configure(<path of 
globus's
log4j.properties>);
        }
}

when I use a client to call this service, the first line in the
service's static block prints out the message and then the whole
container process suspends in the second line. It must be something
wrong with the logging method. I have tested the two implementations
of Globals and it's always the same. The container process does NOT
stop or terminate or print out any message.

I have tested class Globals in a non web service version of my
project, and the two implementations works fine.

If the problem remains I will not finish my project in time.Can you
tell me what's wrong. If you give me a correct sample of how to use
log4j in globus wsrf service, it will be highly appreciated.

Thanks.


--
Steve Thorpe
Systems Programmer/Analyst, MCNC
Email: [EMAIL PROTECTED]
Office: 919-248-1161
Mobile: 919-724-9654
Skype/AIM: thorpe682

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to