Implementing Logs in the HelloWorld Application 
Use this procedure to implement log messages in the created HelloWorld application.
You have successfully exposed the HelloWorld EJB as a Web service.
In the Project Explorer, choose .
Right-click com.sap.tutorial.helloworld and choose .
In the Name field, enter a non-specific name, for example LogTest.
In the empty class window, enter the following code sample:
Syntax
package com.sap.tutorial.helloworld;
import com.sap.tc.logging.Location;
import com.sap.tc.logging.Category;
import com.sap.tc.logging.Severity;
import com.sap.tc.logging.SimpleLogger;
public class LogTest {
private static final Location loc = Location.getLocation(Location.getLocation("log.test"));
public static void demonstrate() {
SimpleLogger.log(Severity.INFO, Category.SYS_SERVER, loc, "api:ab0200",
"Component LogRecommendations started");
}
}Using this code, the application will output the INFO message:
“Component LogRecommendations started”
If you want some more details to be logged (with exception), for example a timer, add the following code sample in the end:
Syntax
try { //do something to be logged
} catch (Exception e) {
SimpleLogger.log(Severity.ERROR, Category.SYS_SERVER, loc, "api:ab0201",
"Problem communicating with DB during demonstrating LogExamples.
See traces for specific details. ");
SimpleLogger.traceThrowable(Severity.ERROR, loc, "a relevant meaningful message.
But not an ex.getMessage() because an exception message will be
traced with the exception stack trace...", e);
}In the HelloBean.java window, insert the code line LogTest.demonstrate();.
Your updated code seems as follows:
Syntax
package com.sap.tutorial.helloworld;
import javax.ejb.Stateless;
import javax.jws.WebService;
@WebService(endpointInterface="com.sap.tutorial.helloworld.HelloBeanRemote",
portName="HelloBeanPort", serviceName="HelloBeanService",
targetNamespace="http://sap.com/tutorial/helloworld/")
@Stateless(name="HelloBean")
public class HelloBean implements HelloBeanRemote, HelloBeanLocal {
private String message = "Hello, ";
public String sayHello(String name) {
LogTest.demonstrate();
return message + name + ".";
}
}Save the current project.
You have successfully entered the logging functionality.
Next step: Deploying the HelloWorld Application