Symptoms
I wanted to test the custom logging functionality.
Diagnosis
There's an easy Library to use.
Solution
I made a sample class that matches the Activity Log for Element entry events.
package logging;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import com.audium.server.global.LoggerApplicationAPI;
import com.audium.server.logger.ApplicationLoggerBase;
import com.audium.server.logger.LoggerPlugin;
import com.audium.server.logger.events.ApplicationEvent;
import com.audium.server.logger.events.ElementEnterEvent;
import com.audium.server.logger.events.EventException;
import com.audium.server.logger.events.IEventIDs;
/**
* Programming guide:
* https://www.cisco.com/c/en/us/td/docs/voice_ip_comm/cust_contact/contact_center/customer_voice_portal/cvp11_6/programming/guide/ccvp_b_programming-guide-for-cisco-unified-11-6/ccvp_b_programming-guide-for-cisco-unified_chapter_01100.html#CCVP_TP_A55E3990_00
*/
public class CustomAppLogger1 extends ApplicationLoggerBase implements LoggerPlugin {
private static final String DELIMITER = ",";
private BufferedWriter writer = null;
/**
* Called on app start.
*/
@Override
public void initialize(File configFile, LoggerApplicationAPI globalAndApplicationData) throws EventException {
eventsToListenFor.add(ELEMENT_ENTER_EVENT_ID);
eventsToListenFor.add(ELEMENT_DEFAULT_INTERACTION_EVENT_ID);
Path logFilePath = Paths.get(getLogFileDirectory(), "customLogFile.log");
try {
writer = new BufferedWriter(new FileWriter(logFilePath.toString()));
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Called on app end, restart, redeploy
*/
@Override
public void destroy(LoggerApplicationAPI globalAndApplicationData) {
if (writer != null)
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void log(ApplicationEvent eventAndEnvironmentInformation) throws EventException {
String eventID = eventAndEnvironmentInformation.getID();
if (eventID.equals(IEventIDs.ELEMENT_ENTER_EVENT_ID)) {
logElementEnterEvent(eventAndEnvironmentInformation);
}
}
private void logElementEnterEvent(ApplicationEvent event) {
ElementEnterEvent enterEvent = (ElementEnterEvent) event;
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy kk:mm:ss.SSS");
try {
writer.append(enterEvent.getLoggerAPI().getSessionId()).append(DELIMITER);
Calendar cal = enterEvent.getTimestamp();
sdf.setTimeZone(cal.getTimeZone());
writer.append(sdf.format(cal.getTime())).append(DELIMITER);
writer.append(enterEvent.getElementName()).append(DELIMITER);
writer.append("enter").append(DELIMITER);
writer.append(""); // description of what happened, no delimiter after last item
writer.append("\n");
} catch (Exception e) {
e.printStackTrace();
try {
writer.append("\nexception=" + e.toString());
} catch (IOException ioe) {
ioe.printStackTrace();
}
} finally {
if (writer != null) {
try {
writer.append("\n");
writer.flush();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
}
}