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

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 



Inject the logger into your Testbean component.

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


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


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


Post a Comment

Related Posts Plugin for WordPress, Blogger...