ATG Override logging

We had the requirement to append Order ID for each logging statement. This is how we achieved that.

Create Component:

\atg\dynamo\service\logging\LogQueue.properties

$class=atg.nucleus.logging.CustomLogListenerQueue

logListeners=LogDispatch

customLogging=true

Path of property file should not be changed.

 

CustomLogListenerQueue.java

package atg.nucleus.logging;

import atg.commerce.order.OrderHolder;
import atg.core.util.StringUtils;
import atg.nucleus.logging.LogEvent;
import atg.nucleus.logging.LogListenerQueue;
import atg.servlet.ServletUtil;

public class CustomLogListenerQueue extends LogListenerQueue {

private boolean mCustomLogging;
private static String ORDER_PATH = “/atg/commerce/ShoppingCart”;

/**
* @return the customLogging
*/
public boolean isCustomLogging() {
return mCustomLogging;
}

/**
* @param pCustomLogging
* the customLogging to set
*/
public void setCustomLogging(boolean pCustomLogging) {
mCustomLogging = pCustomLogging;
}

/* (non-Javadoc)
* @see atg.nucleus.logging.LogListenerQueue#logEvent(atg.nucleus.logging.LogEvent)
* Following would append order id in front of all log messages
*/
@Override
public synchronized void logEvent(LogEvent pArg0) {

if (isCustomLogging()) {
String lCustomLogMessage = “”;

if (null != pArg0 && !StringUtils.isBlank(pArg0.mMessage) && null != ServletUtil.getCurrentRequest()) {

OrderHolder lOrderHolder = (OrderHolder) ServletUtil.getCurrentRequest().resolveName(ORDER_PATH);
if (null != lOrderHolder && null != lOrderHolder.getCurrent(Boolean.FALSE)) {
lCustomLogMessage = “OrderID: ” + lOrderHolder.getCurrent().getId() + ” “;
}

pArg0.mMessage = lCustomLogMessage + pArg0.mMessage;
}
}

super.logEvent(pArg0);
}

}