Logging without Extending GenericService

ATG has a built in logging mechanism provided by the class atg.nucleus.GenericService,the logging can be done through the methods logDebug(),logInfo() etc.Most of the frame work/Out Of the Box classes like DynamoServlet,GenericFormHandler,CartModifierFormHandler etc are extending the Generic Service class.

But if you are writing a component class which cannot extend GenericService in its hierarchy,we need to do a small tweak like below.

Create a component from the Out Of Box class 'atg.nuceus.logging.ApplicationLoggingImpl'.

# /com/test/TestLogger
#Thu Jul 12 21:22:19 GMT+05:30 2012
$class=atg.nucleus.logging.ApplicationLoggingImpl
$scope=global
loggingDebug=true

Now create your own component class.Inject the logger into these POJO classes.

package test;
import atg.nucleus.Nucleus;
import atg.nucleus.logging.ApplicationLoggingImpl;

public class Testbean {

private ApplicationLoggingImpl logger;

public ApplicationLoggingImpl getLogger() {

return logger; }

public void setLogger(ApplicationLoggingImpl logger) {

this.logger = logger;

// the identifier will enable the logger to know which component has
// given the log message. otherwise it will tell unknown service as the //component name 

logger.setLoggingIdentifier("/com/test/Testtbean");
....

}

Inject the logger into your Testbean component.

# /com/test/Testbean
#Thu Jul 12 21:22:19 GMT+05:30 2012

$class=test.firstbean
$scope=request
logger=/com/test/TestLogger



Now you can use  logger inside the class in normal fashion.

if(logger.isLoggingDebug())

logger.logDebug("inside XXX method");

Now if we wish to change the log level, we need to go to the ACC or adminUI, and locate the TestLogger component and change its appropriate properties.

See Also

Comments

Popular posts from this blog

BCC site status inaccessible Agent Production in error state

Weblogic Issues during EAR Deployment Exception in AppMerge flows progression

DUseSunHttpHandler=true weblogic.net.http.SOAPHttpsURLConnection Weblogic/Java HttpHandler issues