Showing posts with label Logging. Show all posts
Showing posts with label Logging. Show all posts

Friday, 30 September 2016

ATG Endeca Integration | Write log [Logging API] requests while using Assembler API

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

=========================================================================

Thursday, 28 January 2016

Endeca Logging And Reporting System

Here We will explore the endeca logging and reporting system. Reports are great tool to capture customer behavior on application usage.

Like :
  • Most popular search on application ?
  • Search conversion rate ?
  • How users are browsing the site ?
  • Search and navigation traffic on site ? 
     
Steps to add logging feature in application.

1. Add Logging requests in application code.
2. Modify Report Settings file if required.
3. Configure Log Server and Report Generator.

How it works ?

1. Send Logging Requests to LogServer using Logging API.
2. LogServer write logging requests to log files.
3. Report Generator reads log files and generate reports.

Key Components of logging and Reporting System.


1. Logging API : Used to Create and submit log requests. Below are two core classes of Logging API.
    a. LogEntry : Key/value pair container for log requests.
    b. LogConnection : Used to connect with LogServer.

Log requests are independent of MDEX Engine requests.

2. Log Server : Translate application log requests to flat file.

3. Report Generator : Generates Endeca reports using below three files.

     a. Log File (generated by log server).
     b. Report Settings File. Default Path , %ENDECA_CONF%\etc\ report_settings.xml.
      c. XSLT Stylesheet. -- Setting to specify whether to generate XML or HTML reports. Default Path , %ENDECA_CONF%\etc\tools_report_stylesheet.xsl

Note : In the case settings file path for a report generator is specified in workbench that settings will be effective.


Customizing Report : You can customize reports.  Below are the most common customization.

1. Disable report sections or items.
2. Setting default and list for Top N items drop down.

Here is the report with all the sections and items.



Report after disabling Sorting section and Top Search Key item.


Here is the report with default Top N value (20).




Report after customizing it to 25.


Report Setting file used for above customization.

=======================================================================
<report_settings>
    <top_n report_item="top_search_terms" n="5, 10, 25, 50" initial_value="25" />
    <disable list="sort, top_search_keys" />
</report_settings>
=======================================================================