Logging without Extending GenericService
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
Post a Comment