package alma.acs.logclient;

import com.cosylab.logging.engine.ACS.LCEngine;
import com.cosylab.logging.engine.ACS.ACSLogConnectionListener;
import com.cosylab.logging.engine.ACS.ACSRemoteLogListener;
import com.cosylab.logging.engine.ACS.ACSRemoteRawLogListener;

import com.cosylab.logging.engine.log.ILogEntry;

/**
 * A class to test the receptions of the logs through the listeners.
 * The class instantiate a LCEngine and register itself as listeners.
 * The logs and messages received are printed in the stdout
 * 
 * @author acaproni
 *
 */
public class LogListener implements 
	ACSLogConnectionListener, 
	ACSRemoteLogListener, 
	ACSRemoteRawLogListener {

	// The engine that connects to the logging client
	private LCEngine engine;
	
	/**
	 * The constructor
	 *
	 */
	public LogListener() {
		engine = new LCEngine();
		engine.addLogConnectionListener(this);
		engine.addLogListener(this);
		engine.addRawLogListener(this);
		engine.connect();
	}
	
	/**
	 * Main
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		LogListener ll = new LogListener();
		try {
			Thread.sleep(20000);
		} catch (InterruptedException ie) {}
		ll.disconnet();
		System.exit(0);
	}
	
	public void acsLogConnEstablished() {
		System.out.println("Connection established");
	}
	
	/**
	 * @see com.cosylab.logging.engine.ACS.ACSLogConnectionListener
	 */
	public void acsLogConnDisconnected() {
		System.out.println("Connection disconnected");
	}
	
	/**
	 * @see com.cosylab.logging.engine.ACS.ACSLogConnectionListener
	 */
	public void acsLogConnLost() {
		System.out.println("Connection lost");
	}
	
	/**
	 * @see com.cosylab.logging.engine.ACS.ACSLogConnectionListener
	 */
	public void acsLogConnConnecting() {
		System.out.println("Connecting");
	}
	
	/**
	 * @see com.cosylab.logging.engine.ACS.ACSLogConnectionListener
	 */
	public void acsLogConnSuspended() {
		System.out.println("Connection suspended");
	}
	
	/**
	 * @see com.cosylab.logging.engine.ACS.ACSLogConnectionListener
	 */
	public void acsLogsDelay() {
		System.out.println("Delay detected");
	}
	
	/**
	 * @see com.cosylab.logging.engine.ACS.ACSLogConnectionListener
	 */
	public void reportStatus(String status) {
		//System.out.println("Status msg received: "+status);
	}
	
	/**
	 * Print only the messages received from the client
	 * 
	 * @see com.cosylab.logging.engine.ACS.ACSRemoteLogListener
	 */
	public void xmlEntryReceived(String str) {
		if (str.indexOf("testLTSClientpy")>=0||str.indexOf("alma.acs.loggingtstest.testLTSClient")>=0||str.indexOf("testLTSClient.cpp")>=0) {
	//	if (str.indexOf("testLTSClient")>=0){
			System.out.println("RAW log: "+str);
		}
	}
	
	/**
	 * Print only the messages received from the client
	 * 
	 * @see com.cosylab.logging.engine.ACS.ACSRemoteRawLogListener
	 */
	public void logEntryReceived(ILogEntry log) {
		if (log.getField(ILogEntry.FIELD_FILE).toString().compareTo("../bin/testLTSClientpy")==0||log.getField(ILogEntry.FIELD_FILE).toString().compareTo("alma.acs.loggingtstest.testLTSClient")==0||log.getField(ILogEntry.FIELD_FILE).toString().compareTo("testLTSClient.cpp")==0) {
		//if(log.getField(ILogEntry.FIELD_FILE).toString().indexOf("testLTSClient")>=0){
			System.out.println("Log received: "+log.toString());
		}
	}
	
	/**
	 * Disconnect from the logging channel
	 *
	 */
	public void disconnet() {
		engine.disconnect();
	}
}

@@ -2838,50 +2838,581 @@
 (log
-.getField(ILogEntry.FIELD_FILE).toString()
+==null) %7B%0A%09%09%09throw new IllegalArgumentException(%22Invalid null log%22);%0A%09%09%7D%0A%09%09Object fileObj = log.getField(ILogEntry.FIELD_FILE);%0A%09%09if (fileObj==null) %7B%0A%09%09%09// The file field is not defined%0A%09%09%09// For sure it is not generated by logClient so I can skip this message%0A%09%09%09return;%0A%09%09%7D%0A%09%09String fileField=fileObj.toString();%0A%09%09if (fileField==null) %7B%0A%09%09%09System.out.println(%22Invalid conversion of field to String%22);%0A%09%09%09System.out.println(%22Class of the object: %22+fileObj.getClass().getName());%0A%09%09%09System.out.println(%22XML = %5B%22+log.toXMLString()+%22%5D%22);%0A%09%09%09return;%0A%09%09%7D%0A%09%09if (%0A%09%09%09%09fileField
 .com
@@ -3450,55 +3450,25 @@
 )==0
+ 
 %7C%7C
-log.getField(ILogEntry.FIELD_FILE).toString()
+%0A%09%09%09%09fileField
 .com
@@ -3520,55 +3520,25 @@
 )==0
+ 
 %7C%7C
-log.getField(ILogEntry.FIELD_FILE).toString()
+%0A%09%09%09%09fileField
 .com

Discard log messages with file field not defined