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();
}
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;
}
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());
}
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());
}
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;
}
Aggregations