Search in sources :

Example 66 with ILogEntry

use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.

the class LogFileCache method toCacheString.

protected String toCacheString(ILogEntry log) {
    sb.delete(0, sb.length());
    for (LogField field : LogField.values()) {
        Object obj = log.getField(field);
        if (obj != null) {
            if (obj instanceof Date) {
                sb.append(((Date) obj).getTime());
            } else if (obj instanceof LogTypeHelper) {
                sb.append(((LogTypeHelper) obj).ordinal());
            } else {
                sb.append(obj.toString());
            }
        }
        sb.append((char) 0);
    }
    if (log.hasDatas()) {
        Vector<ILogEntry.AdditionalData> datas = log.getAdditionalData();
        for (int t = 0; t < datas.size(); t++) {
            ILogEntry.AdditionalData data = datas.get(t);
            sb.append(data.name);
            sb.append(SEPARATOR);
            sb.append(data.value);
            sb.append(SEPARATOR);
        }
    }
    return sb.toString();
}
Also used : AdditionalData(com.cosylab.logging.engine.log.ILogEntry.AdditionalData) ILogEntry(com.cosylab.logging.engine.log.ILogEntry) LogTypeHelper(com.cosylab.logging.engine.log.LogTypeHelper) LogField(com.cosylab.logging.engine.log.LogField) Date(java.util.Date) AdditionalData(com.cosylab.logging.engine.log.ILogEntry.AdditionalData)

Example 67 with ILogEntry

use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.

the class AntennaSourceReductionTest method createLog.

/**
	 * Create a log entry with the passed message and source
	 * 
	 * @param logMsg The message
	 * @param logSrc The source
	 * @return The log entry
	 * @throws Exception
	 */
private ILogEntry createLog(String logMsg, String logSrc) throws Exception {
    ACSLogParser parser = ACSLogParserFactory.getParser();
    long now = Calendar.getInstance().getTimeInMillis();
    SimpleDateFormat df = new IsoDateFormat();
    Date dt = new Date(now);
    StringBuffer dateSB = new StringBuffer();
    FieldPosition pos = new FieldPosition(0);
    df.format(dt, dateSB, pos);
    StringBuilder logStr = new StringBuilder("<Info TimeStamp=\"");
    logStr.append(dateSB.toString());
    logStr.append("\" Routine=\"CacheTest::testGet\" SourceObject=\"");
    logStr.append(logSrc);
    logStr.append("\" Host=\"this\" Process=\"test\" Thread=\"main\" Context=\"\"><![CDATA[");
    logStr.append(logMsg);
    logStr.append("]]></Info>");
    ILogEntry newLog = parser.parse(logStr.toString());
    return newLog;
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) ACSLogParser(alma.acs.logging.engine.parser.ACSLogParser) IsoDateFormat(alma.acs.util.IsoDateFormat) FieldPosition(java.text.FieldPosition) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 68 with ILogEntry

use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.

the class AntennaSourceReductionTest method testRedction.

/**
	 * Test if the reduction works submitting several logs
	 * 
	 * @throws Exception
	 */
public void testRedction() throws Exception {
    String msg = "In position";
    // Reducible
    ILogEntry log1 = createLog(msg, "CONTROL/DA41/WVR");
    SourceAntennaRule sar = new SourceAntennaRule(log1);
    ILogEntry log2 = createLog(msg, "CONTROL/DV13/WVR");
    sar.applyRule(log2);
    if (!sar.isReducingLogs()) {
        System.out.println("isReducing should return TRUE at this point!");
    }
    ILogEntry log3 = createLog(msg, "CONTROL/PM02/WVR");
    sar.applyRule(log3);
    ILogEntry log4 = createLog(msg, "CONTROL/CM04/WVR");
    sar.applyRule(log4);
    // This log is not reduced even if the source contains an antenna name
    ILogEntry log5 = createLog(msg, "CONTROL/CM03/ACD");
    sar.applyRule(log5);
    // This log is not reduced because the message is different
    ILogEntry log6 = createLog("Different log message", "CONTROL/CM03/WVR");
    sar.applyRule(log6);
    ILogEntry log7 = createLog(msg, "CONTROL/DA44/WVR");
    sar.applyRule(log7);
    System.out.println("Reduced log: " + sar.getReducedLog().toString());
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) SourceAntennaRule(alma.acs.logging.table.reduction.SourceAntennaRule)

Example 69 with ILogEntry

use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.

the class AntennaReductionTest method checkReductions.

public void checkReductions() {
    // Create a log that matches
    ILogEntry log = null;
    try {
        log = createLog("Antenna PM02 in position");
    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        System.exit(-1);
    }
    reduction.applyRule(log);
    if (!reduction.isReducingLogs()) {
        System.out.println("This rule SHOULD have reduced logs!");
    }
    // It has an antenna but in a wrong position
    try {
        log = createLog("Antenna in position PM02");
    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        System.exit(-1);
    }
    reduction.applyRule(log);
    // No antenna
    try {
        log = createLog("Antenna in position");
    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        System.exit(-1);
    }
    reduction.applyRule(log);
    // Create another log that matches
    try {
        log = createLog("Antenna DV07 in position");
    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        System.exit(-1);
    }
    reduction.applyRule(log);
    System.out.println("Matching antennae: " + reduction.getReducedItems());
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry)

Example 70 with ILogEntry

use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.

the class AntennaReductionTest method createLog.

private ILogEntry createLog(String logMsg) throws Exception {
    ACSLogParser parser = ACSLogParserFactory.getParser();
    long now = Calendar.getInstance().getTimeInMillis();
    SimpleDateFormat df = new IsoDateFormat();
    Date dt = new Date(now);
    StringBuffer dateSB = new StringBuffer();
    FieldPosition pos = new FieldPosition(0);
    df.format(dt, dateSB, pos);
    StringBuilder logStr = new StringBuilder("<Info TimeStamp=\"");
    logStr.append(dateSB.toString());
    logStr.append("\" Routine=\"CacheTest::testGet\" Host=\"this\" Process=\"test\" Thread=\"main\" Context=\"\"><![CDATA[");
    logStr.append(logMsg);
    logStr.append("]]></Info>");
    ILogEntry newLog = parser.parse(logStr.toString());
    return newLog;
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) ACSLogParser(alma.acs.logging.engine.parser.ACSLogParser) IsoDateFormat(alma.acs.util.IsoDateFormat) FieldPosition(java.text.FieldPosition) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

ILogEntry (com.cosylab.logging.engine.log.ILogEntry)85 Vector (java.util.Vector)15 ACSLogParser (alma.acs.logging.engine.parser.ACSLogParser)11 Date (java.util.Date)11 IsoDateFormat (alma.acs.util.IsoDateFormat)9 LogCacheException (com.cosylab.logging.client.cache.LogCacheException)9 AdditionalData (com.cosylab.logging.engine.log.ILogEntry.AdditionalData)9 SimpleDateFormat (java.text.SimpleDateFormat)9 FieldPosition (java.text.FieldPosition)8 LogTypeHelper (com.cosylab.logging.engine.log.LogTypeHelper)7 LogEntry (com.cosylab.logging.engine.log.LogEntry)6 ParserTypes (alma.acs.logging.engine.parser.ACSLogParserFactory.ParserTypes)5 LogBufferedFileCache (com.cosylab.logging.client.cache.LogBufferedFileCache)5 LogFileCache (com.cosylab.logging.client.cache.LogFileCache)5 Random (java.util.Random)5 IOHelper (alma.acs.logging.engine.io.IOHelper)4 LogCache (com.cosylab.logging.client.cache.LogCache)4 IOException (java.io.IOException)4 ILogMap (com.cosylab.logging.client.cache.ILogMap)3 LogField (com.cosylab.logging.engine.log.LogField)3