use of com.cosylab.logging.engine.log.ILogEntry.AdditionalData in project ACS by ACS-Community.
the class ACSLogParserVTD method makeLogEntryFromParsedXML.
/**
* Creates a LogEntry from raw XML, using a VTD XML parser.
*
* @param xmlString the XML string that is being parsed.
* @param bytesArray the array of bytes (also containing the xml string that we are parsing, in byte form)
* to be used by VTD.
* @param vtdGen the instance of VTDGen to use for parsing the XML
* @return A LogEntry populated with the data for the log entry contained in the XML string passed in.
* @throws LogParseException if the parsing fails
*/
private LogEntry makeLogEntryFromParsedXML(byte[] bytesArray, String xmlString) throws LogParseException {
// TODO: this method, though relatively simple, is a bit long; consider making it shorter
LogEntry retVal = null;
Object vtdNav;
try {
vtdNav = VTDGen_getNav.invoke(vtdGen, nullObj);
if (// to root element
(Boolean) VTDNav_toElement.invoke(vtdNav, NAV_ROOT)) {
if ((Boolean) VTDNav_matchElement.invoke(vtdNav, ILogEntry.LOG_ELEMENT_TAG_NAME)) {
// navigate to child
if ((Boolean) VTDNav_toElement.invoke(vtdNav, NAV_FIRST_CHILD)) {
if ((Boolean) VTDNav_matchElement.invoke(vtdNav, ILogEntry.HEADER_ELEMENT_TAG_NAME)) {
// navigate to sibling
VTDNav_toElement.invoke(vtdNav, NAV_NEXT_SIBLING);
}
}
}
if ((Boolean) VTDNav_matchElement.invoke(vtdNav, ILogEntry.HEADER_ELEMENT_TAG_NAME)) {
// navigate to sibling
VTDNav_toElement.invoke(vtdNav, NAV_NEXT_SIBLING);
}
Long milliseconds = null;
Integer line = null;
Integer priority = null;
Integer stackLevel = null;
String fileName = null;
String routineName = null;
String hostName = null;
String processName = null;
String contextName = null;
String threadName = null;
String logId = null;
String uri = null;
String stackId = null;
String logMessage = null;
String srcObjectName = null;
String audience = null;
String array = null;
String antenna = null;
ByteArrayOutputStream os = new ByteArrayOutputStream();
LogTypeHelper entryType = determineEntryType(vtdNav);
// test for timestamp attribute
if ((Boolean) VTDNav_hasAttr.invoke(vtdNav, LogField.TIMESTAMP.getTagAttribute())) {
milliseconds = getLongFromTimestamp(vtdNav, os, LogField.TIMESTAMP.getTagAttribute(), bytesArray);
}
// test for File attribute
if ((Boolean) VTDNav_hasAttr.invoke(vtdNav, LogField.FILE.getTagAttribute())) {
fileName = this.getString(vtdNav, os, LogField.FILE.getTagAttribute(), bytesArray);
}
// test for Line attribute
if ((Boolean) VTDNav_hasAttr.invoke(vtdNav, LogField.LINE.getTagAttribute())) {
line = getInteger(vtdNav, os, LogField.LINE.getTagAttribute(), bytesArray);
}
// test for Routine attribute
if ((Boolean) VTDNav_hasAttr.invoke(vtdNav, LogField.ROUTINE.getTagAttribute())) {
routineName = this.getString(vtdNav, os, LogField.ROUTINE.getTagAttribute(), bytesArray);
}
// test for host attribute
if ((Boolean) VTDNav_hasAttr.invoke(vtdNav, LogField.HOST.getTagAttribute())) {
hostName = this.getString(vtdNav, os, LogField.HOST.getTagAttribute(), bytesArray);
}
// test for process attribute
if ((Boolean) VTDNav_hasAttr.invoke(vtdNav, LogField.PROCESS.getTagAttribute())) {
processName = this.getString(vtdNav, os, LogField.PROCESS.getTagAttribute(), bytesArray);
}
// test for context attribute
if ((Boolean) VTDNav_hasAttr.invoke(vtdNav, LogField.CONTEXT.getTagAttribute())) {
contextName = this.getString(vtdNav, os, LogField.CONTEXT.getTagAttribute(), bytesArray);
}
// test for thread attribute
if ((Boolean) VTDNav_hasAttr.invoke(vtdNav, LogField.THREAD.getTagAttribute())) {
threadName = this.getString(vtdNav, os, LogField.THREAD.getTagAttribute(), bytesArray);
}
// test for logid attribute
if ((Boolean) VTDNav_hasAttr.invoke(vtdNav, LogField.LOGID.getTagAttribute())) {
logId = this.getString(vtdNav, os, LogField.LOGID.getTagAttribute(), bytesArray);
}
// test for priority attribute
if ((Boolean) VTDNav_hasAttr.invoke(vtdNav, LogField.PRIORITY.getTagAttribute())) {
priority = getInteger(vtdNav, os, LogField.PRIORITY.getTagAttribute(), bytesArray);
}
// test for uri attribute
if ((Boolean) VTDNav_hasAttr.invoke(vtdNav, LogField.URI.getTagAttribute())) {
uri = this.getString(vtdNav, os, LogField.URI.getTagAttribute(), bytesArray);
}
// test for stackid attribute
if ((Boolean) VTDNav_hasAttr.invoke(vtdNav, LogField.STACKID.getTagAttribute())) {
stackId = this.getString(vtdNav, os, LogField.STACKID.getTagAttribute(), bytesArray);
}
// test for stacklevel attribute
if ((Boolean) VTDNav_hasAttr.invoke(vtdNav, LogField.STACKLEVEL.getTagAttribute())) {
stackLevel = getInteger(vtdNav, os, LogField.STACKLEVEL.getTagAttribute(), bytesArray);
}
// test for srcObject attribute
if ((Boolean) VTDNav_hasAttr.invoke(vtdNav, LogField.SOURCEOBJECT.getTagAttribute())) {
srcObjectName = getString(vtdNav, os, LogField.SOURCEOBJECT.getTagAttribute(), bytesArray);
}
// test for Audience attribute
if ((Boolean) VTDNav_hasAttr.invoke(vtdNav, LogField.AUDIENCE.getTagAttribute())) {
audience = getString(vtdNav, os, LogField.AUDIENCE.getTagAttribute(), bytesArray);
}
// test for Array attribute
if ((Boolean) VTDNav_hasAttr.invoke(vtdNav, LogField.ARRAY.getTagAttribute())) {
array = getString(vtdNav, os, LogField.ARRAY.getTagAttribute(), bytesArray);
}
// test for Antenna attribute
if ((Boolean) VTDNav_hasAttr.invoke(vtdNav, LogField.ANTENNA.getTagAttribute())) {
antenna = getString(vtdNav, os, LogField.ANTENNA.getTagAttribute(), bytesArray);
}
// Get the body of the message
int tIndex = (Integer) VTDNav_getText.invoke(vtdNav, nullObj);
if (tIndex != -1) {
// int tOffset = vn.getTokenOffset(tIndex);
// int tLen = vn.getTokenLength(tIndex);
logMessage = (String) VTDNav_toString.invoke(vtdNav, tIndex);
}
// get the additional data, if present
Vector<AdditionalData> extraDataList = getAdditionalData(vtdNav, os, bytesArray);
// get again the body of the message.
if (logMessage == null) {
try {
logMessage = getLogMessage(vtdNav);
} catch (Exception e) {
logMessage = null;
}
}
retVal = new LogEntry(milliseconds, entryType.ordinal(), fileName, line, routineName, hostName, processName, contextName, threadName, logId, priority, uri, stackId, stackLevel, logMessage, srcObjectName, audience, array, antenna, extraDataList);
} else {
throw new LogParseException("Error: VTD cannot find root element; string is: " + xmlString);
}
} catch (Exception navEx) {
navEx.printStackTrace();
throw new LogParseException("Error navigating parsed XML with VTD navigator!", navEx);
}
return retVal;
}
use of com.cosylab.logging.engine.log.ILogEntry.AdditionalData in project ACS by ACS-Community.
the class CacheUtils method fromCacheString.
/**
* Build a log out of its string representation
*
* @param str The string representing a log
* @return The log
*/
public static synchronized ILogEntry fromCacheString(String str) throws LogEngineException {
String[] strs = str.split(SEPARATOR);
long millis = 0;
try {
synchronized (dateFormat) {
millis = dateFormat.parse(strs[0]).getTime();
}
} catch (ParseException e) {
System.err.println("Error parsing the date: " + strs[0]);
throw new LogEngineException(e);
}
Integer entrytype = new Integer(strs[1]);
String srcObject = null;
if (strs.length > 2) {
srcObject = strs[2];
}
String fileNM = null;
if (strs.length > 3) {
fileNM = strs[3];
}
Integer line = null;
if (strs.length > 4 && strs[4].length() != 0) {
line = new Integer(strs[4]);
}
String routine = null;
if (strs.length > 5) {
routine = strs[5];
}
String host = null;
if (strs.length > 6) {
host = strs[6];
}
String process = null;
if (strs.length > 7) {
process = strs[7];
}
String context = null;
if (strs.length > 8) {
context = strs[8];
}
String thread = null;
if (strs.length > 9) {
thread = strs[9];
}
String logid = null;
if (strs.length > 10) {
logid = strs[10];
}
Integer priority = null;
if (strs.length > 11 && strs[11].length() > 0) {
priority = new Integer(strs[11]);
}
String uri = null;
if (strs.length > 12) {
uri = strs[12];
}
String stackid = null;
if (strs.length > 13) {
stackid = strs[13];
}
Integer stacklevel = null;
if (strs.length > 14 && strs[14].length() > 0) {
Integer.parseInt(strs[14]);
}
String logmessage = null;
if (strs.length > 15) {
logmessage = strs[15];
}
String audience = null;
if (strs.length > 16) {
audience = strs[16];
}
String array = null;
if (strs.length > 17) {
array = strs[17];
}
String antenna = null;
if (strs.length > 18) {
antenna = strs[18];
}
Vector<ILogEntry.AdditionalData> addDatas = null;
if (strs.length > LogField.values().length) {
addDatas = new Vector<ILogEntry.AdditionalData>();
for (int t = LogField.values().length; t < strs.length; t += 2) {
addDatas.add(new AdditionalData(strs[t], strs[t + 1]));
}
}
return new LogEntry(millis, entrytype, fileNM, line, routine, host, process, context, thread, logid, priority, uri, stackid, stacklevel, logmessage, srcObject, audience, array, antenna, addDatas);
}
use of com.cosylab.logging.engine.log.ILogEntry.AdditionalData in project ACS by ACS-Community.
the class ACSLogParserVTD method getAdditionalData.
/**
* Gets a Vector<AdditionalData> from VTD XML parser (using VTDNav navigation)
*
* @param vtdNav the navigator to use to navigate the parsed xml
* @param os output stream to use for conversion of bytes to useful formatted data.
* @param bytesXML the bytes (containing XML) that are being referenced by the navigator.
* @return Vector<AdditionalData> populated with the additional data for the log message, if any, else null
* @throws NavException if navigation encounters problems
*/
private Vector<AdditionalData> getAdditionalData(Object vNav, ByteArrayOutputStream os, byte[] bytesArray) throws Exception {
Vector<AdditionalData> retVal = null;
if ((Boolean) VTDNav_toElement_String.invoke(vNav, new Object[] { NAV_FIRST_CHILD, ILogEntry.DATA_ELEMENT_TAG_NAME })) {
do {
String dataName = null;
String dataValue = null;
if ((Boolean) VTDNav_hasAttr.invoke(vNav, ILogEntry.NAME_ATTRIBUTE_NAME)) {
dataName = getString(vNav, os, ILogEntry.NAME_ATTRIBUTE_NAME, bytesArray);
}
int valueIndex = (Integer) VTDNav_getText.invoke(vNav, nullObj);
if (valueIndex != -1) {
dataValue = (String) VTDNav_toNormalizedString.invoke(vNav, valueIndex);
}
if (null != dataName && null != dataValue) {
if (null == retVal) {
retVal = new Vector<AdditionalData>();
}
retVal.add(new AdditionalData(dataName, dataValue));
}
} while (// navigate to next sibling
(Boolean) VTDNav_toElement.invoke(vNav, NAV_NEXT_SIBLING));
}
return retVal;
}
use of com.cosylab.logging.engine.log.ILogEntry.AdditionalData in project ACS by ACS-Community.
the class ACSLogParserTest method testSpecialLogs.
/**
* Test special logs i.e. logs that sometime have returned errors while parsing.
*
* @see <code>specialLogs</code>
* @throws Exception
*/
public void testSpecialLogs() throws Exception {
// Cycle through all available parsers
for (ParserTypes type : ParserTypes.values()) {
System.out.println("testSpecialLogs: Testing parser " + type);
parser = ACSLogParserFactory.getParser(type);
assertNotNull(parser);
assertEquals(type, ACSLogParserFactory.getParserType(parser));
for (String xmlLog : specialLogs) {
ILogEntry log = parser.parse(xmlLog);
Vector<AdditionalData> data = log.getAdditionalData();
if (data != null) {
for (int t = 0; t < data.size(); t++) {
AdditionalData d = data.get(t);
System.out.println("Data: name=" + d.name + ", value=" + d.value);
}
} else {
System.out.println("The log has no additional data entries");
}
System.out.println("Body: " + log.getField(LogField.LOGMESSAGE));
}
}
}
use of com.cosylab.logging.engine.log.ILogEntry.AdditionalData in project ACS by ACS-Community.
the class LogFileCache method fromCacheString.
private ILogEntry fromCacheString(String str) {
String[] strs = str.split(SEPARATOR);
Long millis = new Long(strs[0]);
Integer entrytype = new Integer(strs[1]);
String srcObject = null;
if (strs.length > 2) {
srcObject = strs[2];
}
String fileNM = null;
if (strs.length > 3) {
fileNM = strs[3];
}
Integer line = null;
if (strs.length > 4 && strs[4].length() != 0) {
line = new Integer(strs[4]);
}
String routine = null;
if (strs.length > 5) {
routine = strs[5];
}
String host = null;
if (strs.length > 6) {
host = strs[6];
}
String process = null;
if (strs.length > 7) {
process = strs[7];
}
String context = null;
if (strs.length > 8) {
context = strs[8];
}
String thread = null;
if (strs.length > 9) {
thread = strs[9];
}
String logid = null;
if (strs.length > 10) {
logid = strs[10];
}
Integer priority = null;
if (strs.length > 11 && strs[11].length() > 0) {
priority = new Integer(strs[11]);
}
String uri = null;
if (strs.length > 12) {
uri = strs[12];
}
String stackid = null;
if (strs.length > 13) {
stackid = strs[13];
}
Integer stacklevel = null;
if (strs.length > 14 && strs[14].length() > 0) {
stacklevel = Integer.parseInt(strs[14]);
}
String logmessage = null;
if (strs.length > 15) {
logmessage = strs[15];
}
String audience = null;
if (strs.length > 16) {
audience = strs[16];
}
String array = null;
if (strs.length > 17) {
array = strs[17];
}
String antenna = null;
if (strs.length > 18) {
antenna = strs[18];
}
Vector<ILogEntry.AdditionalData> addDatas = null;
if (strs.length > LogField.values().length) {
addDatas = new Vector<ILogEntry.AdditionalData>();
for (int t = LogField.values().length; t < strs.length; t += 2) {
addDatas.add(new AdditionalData(strs[t], strs[t + 1]));
}
}
return new LogEntry(millis, entrytype, fileNM, line, routine, host, process, context, thread, logid, priority, uri, stackid, stacklevel, logmessage, srcObject, audience, array, antenna, addDatas);
}
Aggregations