use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.
the class ACSLogParserDOM method parse.
/* (non-Javadoc)
* @see com.cosylab.logging.engine.ACS.ACSLogParser#parse(java.lang.String)
*/
public synchronized ILogEntry parse(String string) throws LogParseException {
Document document = null;
try {
document = builder.parse(new InputSource(new StringReader(string)));
} catch (IOException ioe) {
// cannot get here
System.err.println("Exception parsing " + ioe.getMessage());
throw new LogParseException(ioe);
} catch (Exception e) {
/* There was an exception parsing the log, but before giving up
* we try to fix markup issues inside the text that is contained in the XML */
document = null;
String newLogString = XmlNormalizer.normalizeXMLEmbeddedTextOnly(string);
try {
document = builder.parse(new InputSource(new StringReader(newLogString)));
System.out.println("Fatal error recovered:");
System.out.println("\tOriginal log entry: " + string);
System.out.println("\tCleaned log entry: " + newLogString + "\n");
} catch (IOException ex1) {
System.err.println("Failed to parse the following log entry:");
System.err.println(string);
System.err.println("with IO exception ");
throw new LogParseException(ex1);
} catch (SAXException ex2) {
System.err.println("Failed to parse the following log entry:");
System.err.println(string);
System.err.println("with parser exception ");
throw new LogParseException(ex2);
}
}
return new LogEntry(new LogEntryXML(document.getFirstChild()));
}
use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.
the class ACSLogParserVTD method parse.
/**
* Implements required method of ACSLogParser interface.
*
* @param xmlString the XML string to parse
* @throws LogParseException when problems are encountered parsing an XML message.
* @see ACSLogParser
*/
public synchronized ILogEntry parse(String xmlString) throws LogParseException {
if (xmlString == null || xmlString.length() == 0) {
throw new IllegalArgumentException("Invalid string to parse");
}
LogEntry retVal = null;
byte[] bytesArray = xmlString.getBytes();
try {
try {
VTDGen_clear.invoke(vtdGen, nullObj);
VTDGen_setDoc.invoke(vtdGen, bytesArray);
// set namespace awareness to false for now
VTDGen_parse.invoke(vtdGen, false);
} catch (Exception e) {
/* There was an exception parsing the log, but before giving up
* we try to fix markup issues inside the text that is contained in the XML */
VTDGen_clear.invoke(vtdGen, nullObj);
xmlString = XmlNormalizer.normalizeXMLEmbeddedTextOnly(xmlString);
bytesArray = xmlString.getBytes();
VTDGen_setDoc.invoke(vtdGen, xmlString.getBytes());
VTDGen_parse.invoke(vtdGen, false);
}
retVal = makeLogEntryFromParsedXML(bytesArray, xmlString);
} catch (Exception ex) {
throw new LogParseException("Error parsing with VTD!", ex);
}
return retVal;
}
use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.
the class ACSLogRetrieval method run.
/**
* The thread to read and notify the logs read from the file to the listeners
*/
public void run() {
// delay is used to remember if there is a delay between the logs received
// and those shown in the GUI.
// We assume that such delay exists if the number of logs in queue is
// bigger then DELAY_NUMBER
boolean delay = false;
while (!terminateThread) {
// Check if a delay has to be notified to the listeners
if (cache.size() > ACSLogRetrieval.DELAY_NUMBER) {
if (!delay) {
delay = true;
listenersDispatcher.publishDiscarding();
}
} else if (delay) {
delay = false;
listenersDispatcher.publishConnected(true);
}
// Do not flush the logs if the application is paused
if (paused) {
try {
Thread.sleep(250);
} catch (InterruptedException e) {
}
continue;
}
if (readCounter > maxOutputRate) {
// readConter is cleared
try {
Thread.sleep(50);
} catch (InterruptedException e) {
}
continue;
}
String tempStr = null;
try {
tempStr = cache.pop();
} catch (Throwable t) {
System.err.println("Exception from cache.pop: " + t.getMessage());
t.printStackTrace();
continue;
}
if (tempStr == null) {
// Timeout
try {
Thread.sleep(250);
} catch (InterruptedException ie) {
}
continue;
}
if (tempStr.length() > 0) {
ILogEntry log;
try {
log = parser.parse(tempStr);
} catch (Throwable t) {
listenersDispatcher.publishError(tempStr);
listenersDispatcher.publishReport(tempStr);
System.err.println("Exception parsing a log: " + t.getMessage());
t.printStackTrace(System.err);
continue;
}
publishLog(tempStr, log);
}
}
}
use of com.cosylab.logging.engine.log.ILogEntry 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 in project ACS by ACS-Community.
the class IOHelper method saveLogs.
/**
* Save a collection of logs on a <code>BufferedWriter</code>.
* <P>
* The buffer must be initialized and terminated i.e. the <code>prepareSaveFile</code>
* and the <code>terminateSave</code> are not executed by this method.
*
* @param outBuf The buffer to write logs into
* @param logs The non empty collection of logs to save
* @param progressListener The listener to be notified about the number of bytes written
* @throws IOException In case of error writing
*/
public synchronized void saveLogs(BufferedWriter outBuf, Iterator<ILogEntry> iterator, IOPorgressListener progressListener) throws IOException {
if (iterator == null || !iterator.hasNext()) {
throw new IllegalArgumentException("No logs to save");
}
if (progressListener == null) {
throw new IllegalArgumentException("The progress listener can't be null");
}
stopped = false;
long len = 0;
int logsWritten = 0;
while (iterator.hasNext() && !stopped) {
ILogEntry log = iterator.next();
len += saveLog(outBuf, log);
progressListener.bytesWritten(len);
progressListener.logsWritten(++logsWritten);
}
}
Aggregations