In the case we want to use endeca logging and reporting. The first thing is we need to write log entries in LogServer's log file. Here I am going to explain, how to write log request to log file with assembler API.
Below are steps :
1. Create class which extends RequestEventListener.
2. Create global scoped component of this class.
3. Add this component in assemblerEventListeners property of NucleusAssemblerFactory.
Below is the example :
1. Create class which extends RequestEventListener.
=========================================================================
package com.shop.endeca.assembler.logserver;
import atg.servlet.ServletUtil;
import com.endeca.infront.assembler.ContentItem;
import com.endeca.infront.assembler.event.request.RequestEvent;
import com.endeca.infront.assembler.event.request.RequestEventListener;
import com.endeca.infront.navigation.event.NavigationEventWrapper;
import com.endeca.logging.*;
import atg.nucleus.logging.ApplicationLogging;
import atg.nucleus.logging.ClassLoggingFactory;
public class LogServerAdapter extends RequestEventListener
{
private static ApplicationLogging mLogger = ClassLoggingFactory.getFactory().getLoggerForClass(LogServerAdapter.class);
private static LogConnection Logconn;
private LogConnection getLogconn() {
Logconn=new LogConnection(getLogServer(),getPortNumber());
return Logconn;
}
public void setLogconn(LogConnection conn) {
this.Logconn =Logconn;
}
// Endeca server hostname where endeca log server is hosted.
private String logServer;
public String getLogServer() {
return logServer;
}
public void setLogServer(String logServer) {
this.logServer = logServer;
}
// Endeca Log Sever port number
private Integer portNumber;
public Integer getPortNumber() {
return portNumber;
}
public void setPortNumber(Integer portNumber) {
this.portNumber = portNumber;
}
/**
* @return ApplicationLogging object for logger.
*/
private ApplicationLogging getLogger() {
return mLogger;
}
@Override
public void handleAssemblerRequestEvent(RequestEvent assemblerReqEnt, ContentItem conItemPar) {
try
{
LogEntry handleLog = new LogEntry();
Logconn=getLogconn();
NavigationEventWrapper eventNavigation = new NavigationEventWrapper(assemblerReqEnt);
if (assemblerReqEnt.getSessionId() != null) {
handleLog.putString("SESSION_ID", assemblerReqEnt.getSessionId());
}
if (eventNavigation.getAutocorrectTo() != null) {
handleLog.putString("AUTOCORRECT_TO", eventNavigation.getAutocorrectTo());
}
if (eventNavigation.getDimensions() != null) {
handleLog.putList("DIMS", eventNavigation.getDimensions());
}
if (eventNavigation.getDimensionValues() != null) {
handleLog.putList("DVALS", eventNavigation.getDimensionValues());
}
if (eventNavigation.getEneTime() != null) {
handleLog.put("ENE_TIME", eventNavigation.getEneTime());
}
if (eventNavigation.getNumRecords() != null) {
handleLog.put("NUM_RECORDS", eventNavigation.getNumRecords());
}
if (eventNavigation.getRecordNames() != null) {
handleLog.putList("RECORD_NAMES", eventNavigation.getRecordNames());
}
if (eventNavigation.getRequestType() != null) {
handleLog.putString("TYPE", eventNavigation.getRequestType().toString());
}
if (eventNavigation.getSearchKey() != null) {
handleLog.putString("SEARCH_KEY", eventNavigation.getSearchKey());
}
if (eventNavigation.getNumRefinements() != null) {
handleLog.put("NUMREFINEMENTS", eventNavigation.getNumRefinements());
}
if (eventNavigation.getSortKeys() != null) {
handleLog.putList("SORT_KEY", eventNavigation.getSortKeys());
}
if (eventNavigation.getSpotlights() != null) {
handleLog.putList("MERCH_RULES", eventNavigation.getSpotlights());
}
if (eventNavigation.getSearchMode() != null) {
handleLog.putString("SEARCH_MODE", eventNavigation.getSearchMode());
}
if (eventNavigation.getSearchTerms() != null) {
handleLog.putString("SEARCH_TERMS", eventNavigation.getSearchTerms());
}
Logconn.logAsynchronously(handleLog);
if(getLogger().isLoggingDebug())
{
getLogger().logDebug("reporting log is updated.");
}
}
catch (LogException e)
{
if (getLogger().isLoggingError())
{
getLogger().logError("There is some LogException"+e.getMessage());
}
}catch(Exception e)
{
if (getLogger().isLoggingError())
{
getLogger().logError("There is some other exception"+e.getMessage());
}
}
}
}
=========================================================================
2. Create global scoped component of this class.
=========================================================================
# /atg/endeca/assembler/logserver/LogServerAdapter
$class=com.shop.endeca.assembler.logserver.LogServerAdapter
$scope=global
portNumber=16010
logServer=localhost
=========================================================================
3. Add this component in assemblerEventListeners property of NucleusAssemblerFactory.
=========================================================================
assemblerEventListeners+=\
/atg/endeca/assembler/logserver/LogServerAdapter
=========================================================================
No comments:
Post a Comment