package alma.acs.logclient; import com.cosylab.logging.engine.LogEngineException; 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; import com.cosylab.logging.engine.log.LogField; /** * 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 * <p> * Todo (hso): Could we have used alma.acs.logging.engine.LogReceiver * instead of adding this class for the loggingts test? * * @author acaproni */ public class LogListener implements ACSLogConnectionListener, ACSRemoteLogListener, ACSRemoteRawLogListener { // The engine that connects to the logging client private LCEngine engine; /** * The constructor * */ public LogListener() throws LogEngineException { 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=null; try { ll = new LogListener(); } catch (Throwable t) { System.err.println("Error instantiating the LogListener: "+t.getMessage()); t.printStackTrace(); System.exit(-1); } try { Thread.sleep(20000); } catch (InterruptedException ie) {} ll.disconnet(); System.exit(0); } @Override 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("../bin/testLTSClientpy")>=0 || str.indexOf("LtsTestClient.java")>=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==null) { throw new IllegalArgumentException("Invalid null log"); } Object fileObj = log.getField(LogField.FILE); if (fileObj==null) { // The file field is not defined // For sure it is not generated by logClient so I can skip this message return; } String fileField=fileObj.toString(); if (fileField==null) { System.out.println("Invalid conversion of field to String"); System.out.println("Class of the object: "+fileObj.getClass().getName()); System.out.println("XML = ["+log.toXMLString()+"]"); return; } if ( fileField.compareTo("../bin/testLTSClientpy")==0 || fileField.compareTo("LtsTestClient.java")==0 || fileField.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.close(true); } }