use of com.cosylab.logging.engine.log.ILogEntry.AdditionalData in project ACS by ACS-Community.
the class LoadSaveTest method testSaveLoadFields.
/**
* Save and Load the special logs then check their fields.
* <P>
* This test is performed comparing the fields of the special logs one by one
* instead of comparing the XMLs.
* The test does the following steps:
* <OL>
* <LI>build vector of logs to save from the XMLs in <code>specialLogs</code>
* <LI>save the vector of logs with an <code>IOHelper</code> object
* <LI>load the logs from file
* <LI>compare each field of the logs read from the file with those in <code>specialLogs</code>
* <LI>compare the additional data names and values
* </OL>
* <P>
* The test implicitly checks the conversion between XML and ILogEntry too.
*/
public void testSaveLoadFields() throws Exception {
ACSLogParser parser = ACSLogParserFactory.getParser();
assertNotNull(parser);
//Build the logs from the XML
Vector<ILogEntry> logsToCheck = new Vector<ILogEntry>();
for (int t = 0; t < specialLogs.length; t++) {
ILogEntry log = parser.parse(specialLogs[t]);
assertNotNull(log);
logsToCheck.add(log);
}
// Save the logs on disk
IOHelper ioHelper = new IOHelper();
assertNotNull(ioHelper);
ioHelper.saveLogs(fileName, logsToCheck, this, false, false);
assertEquals(logsToCheck.size(), numOfLogsWritten);
// Load the logs from disk
ioHelper.loadLogs(fileName, this, null, this, this, false);
assertEquals(logsRead.size(), logsToCheck.size());
// Iterate over the logs comparing each field
for (int t = 0; t < logsToCheck.size(); t++) {
ILogEntry originalLog = logsToCheck.elementAt(t);
assertNotNull(originalLog);
ILogEntry savedLog = logsRead.elementAt(t);
assertNotNull(savedLog);
// Check the fields
for (LogField f : LogField.values()) {
Object original = originalLog.getField(f);
Object saved = savedLog.getField(f);
assertEquals("Fields " + f + " differ", original, saved);
}
// Check additional data
assertEquals(originalLog.hasDatas(), savedLog.hasDatas());
if (originalLog.hasDatas()) {
Vector<AdditionalData> originalData = originalLog.getAdditionalData();
assertNotNull(originalData);
Vector<AdditionalData> savedData = savedLog.getAdditionalData();
assertNotNull(savedData);
assertEquals(originalData.size(), savedData.size());
for (int count = 0; count < originalData.size(); count++) {
AdditionalData originalDataItem = originalData.elementAt(count);
assertNotNull(originalDataItem);
AdditionalData savedDataItem = savedData.elementAt(count);
assertNotNull(savedDataItem);
assertEquals("Data names differ", originalDataItem.name, savedDataItem.name);
assertEquals("Data values differ", originalDataItem.value, savedDataItem.value);
}
}
}
}
use of com.cosylab.logging.engine.log.ILogEntry.AdditionalData in project ACS by ACS-Community.
the class LogDispatcherTest method convertLogToBinary.
/**
* Convert a ILogEntry into a binary log
*
* @param The log to convert
* @return The binary log
*
*/
private LogBinaryRecord convertLogToBinary(ILogEntry log) throws Exception {
LogBinaryRecord logBin = new LogBinaryRecord();
logBin.Audience = (String) log.getField(LogField.AUDIENCE);
logBin.File = (String) log.getField(LogField.FILE);
logBin.Host = (String) log.getField(LogField.HOST);
Integer line = (Integer) log.getField(LogField.LINE);
if (line != null) {
logBin.Line = line;
} else {
logBin.Line = 0;
}
logBin.LogContext = (String) log.getField(LogField.CONTEXT);
logBin.LogId = (String) log.getField(LogField.LOGID);
logBin.MsgData = (String) log.getField(LogField.LOGMESSAGE);
Integer priority = (Integer) log.getField(LogField.PRIORITY);
if (priority != null) {
logBin.Priority = priority;
} else {
logBin.Priority = 0;
}
logBin.Process = (String) log.getField(LogField.PROCESS);
logBin.Routine = (String) log.getField(LogField.ROUTINE);
logBin.SourceObject = (String) log.getField(LogField.SOURCEOBJECT);
logBin.StackId = (String) log.getField(LogField.STACKID);
Integer stackL = (Integer) log.getField(LogField.STACKLEVEL);
if (stackL != null) {
logBin.StackLevel = stackL;
} else {
logBin.StackLevel = 0;
}
logBin.Thread = (String) log.getField(LogField.THREAD);
final Date date = new Date((Long) log.getField(LogField.TIMESTAMP));
logBin.TimeStamp = IsoDateFormat.formatDate(date);
logBin.type = (short) log.getType().ordinal();
logBin.Uri = (String) log.getField(LogField.URI);
if (log.hasDatas()) {
Vector<AdditionalData> data = log.getAdditionalData();
logBin.log_data = new NameValue[data.size()];
for (int t = 0; t < data.size(); t++) {
AdditionalData d = data.get(t);
logBin.log_data[t] = new NameValue(d.name, d.value);
}
}
return logBin;
}
use of com.cosylab.logging.engine.log.ILogEntry.AdditionalData in project ACS by ACS-Community.
the class AntennaRule method getReducedLog.
@Override
public ILogEntry getReducedLog() {
String reducedItems = getReducedItems();
if (reducedItems == null || reducedItems.isEmpty()) {
return initialLog;
}
Long milliseconds = (Long) initialLog.getField(LogField.TIMESTAMP);
Integer entrytype = ((LogTypeHelper) initialLog.getField(LogField.ENTRYTYPE)).ordinal();
String file = (String) initialLog.getField(LogField.FILE);
Integer line = (Integer) initialLog.getField(LogField.LINE);
String routine = (String) initialLog.getField(LogField.ROUTINE);
String host = (String) initialLog.getField(LogField.HOST);
String process = (String) initialLog.getField(LogField.PROCESS);
String context = (String) initialLog.getField(LogField.CONTEXT);
String thread = (String) initialLog.getField(LogField.THREAD);
String logid = (String) initialLog.getField(LogField.LOGID);
Integer priority = (Integer) initialLog.getField(LogField.PRIORITY);
String uri = (String) initialLog.getField(LogField.URI);
String stackid = (String) initialLog.getField(LogField.STACKID);
Integer stacklevel = (Integer) initialLog.getField(LogField.STACKLEVEL);
String logmessage = (String) initialLog.getField(LogField.LOGMESSAGE) + " and also " + reducedItems;
String srcObject = (String) initialLog.getField(LogField.SOURCEOBJECT);
String audience = (String) initialLog.getField(LogField.AUDIENCE);
String array = (String) initialLog.getField(LogField.ARRAY);
String antenna = (String) initialLog.getField(LogField.ANTENNA);
Vector<AdditionalData> addDatas = initialLog.getAdditionalData();
LogEntry ret = new LogEntry(milliseconds, entrytype, file, line, routine, host, process, context, thread, logid, priority, uri, stackid, stacklevel, logmessage, srcObject, audience, array, antenna, addDatas);
return ret;
}
use of com.cosylab.logging.engine.log.ILogEntry.AdditionalData in project ACS by ACS-Community.
the class SourceAntennaRule method getReducedLog.
@Override
public ILogEntry getReducedLog() {
if (sourceObjects == null || sourceObjects.size() <= 1) {
return initialLog;
}
Long milliseconds = (Long) initialLog.getField(LogField.TIMESTAMP);
Integer entrytype = ((LogTypeHelper) initialLog.getField(LogField.ENTRYTYPE)).ordinal();
String file = (String) initialLog.getField(LogField.FILE);
Integer line = (Integer) initialLog.getField(LogField.LINE);
String routine = (String) initialLog.getField(LogField.ROUTINE);
String host = (String) initialLog.getField(LogField.HOST);
String process = (String) initialLog.getField(LogField.PROCESS);
String context = (String) initialLog.getField(LogField.CONTEXT);
String thread = (String) initialLog.getField(LogField.THREAD);
String logid = (String) initialLog.getField(LogField.LOGID);
Integer priority = (Integer) initialLog.getField(LogField.PRIORITY);
String uri = (String) initialLog.getField(LogField.URI);
String stackid = (String) initialLog.getField(LogField.STACKID);
Integer stacklevel = (Integer) initialLog.getField(LogField.STACKLEVEL);
String logmessage = initialLogMessage;
String srcObject = reducedSource;
String audience = (String) initialLog.getField(LogField.AUDIENCE);
String array = (String) initialLog.getField(LogField.ARRAY);
String antenna = (String) initialLog.getField(LogField.ANTENNA);
Vector<AdditionalData> addDatas = initialLog.getAdditionalData();
if (addDatas == null) {
addDatas = new Vector<ILogEntry.AdditionalData>();
}
for (String ant : sourceObjects) {
AdditionalData ad = new AdditionalData(additionalDataName, ant);
addDatas.add(ad);
}
LogEntry ret = new LogEntry(milliseconds, entrytype, file, line, routine, host, process, context, thread, logid, priority, uri, stackid, stacklevel, logmessage, srcObject, audience, array, antenna, addDatas);
return ret;
}
use of com.cosylab.logging.engine.log.ILogEntry.AdditionalData in project ACS by ACS-Community.
the class ACSLogParserTest method testParseLogRecord.
/**
* Parses one log record from XML and verifies a few fields,
* including the exception details that are attached as additional data.
*
* @throws Exception
*/
public void testParseLogRecord() throws Exception {
// Cycle through all available parsers
for (ParserTypes type : ParserTypes.values()) {
System.out.println("testParseLogRecord: Testing parser " + type);
parser = ACSLogParserFactory.getParser(type);
assertNotNull(parser);
assertEquals(type, ACSLogParserFactory.getParserType(parser));
ILogEntry log = parser.parse(xmlLogWarningWithException);
// verify some fields
assertEquals("wrong typename string", "Warning", ((LogTypeHelper) log.getField(LogField.ENTRYTYPE)).logEntryType);
assertEquals("wrong type code", LogTypeHelper.WARNING, ((LogTypeHelper) log.getField(LogField.ENTRYTYPE)));
Vector<ILogEntry.AdditionalData> additionalData = log.getAdditionalData();
assertFalse("There should have been 2 pieces of additional data!", additionalData == null || additionalData.size() != 2);
// Check the first data
ILogEntry.AdditionalData myData = additionalData.get(0);
assertEquals("LoggedException", myData.name);
assertTrue(myData.value.startsWith("alma.xmlstore.OperationalPackage.NotFound: uid://X00000000000028aa/X00000002"));
// Check the second data
ILogEntry.AdditionalData d = additionalData.get(1);
assertEquals("Pippo", d.name);
assertEquals("Pluto", d.value);
}
}
Aggregations