Search in sources :

Example 41 with ILogEntry

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()));
}
Also used : InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) IOException(java.io.IOException) Document(org.w3c.dom.Document) LogParseException(com.cosylab.logging.engine.ACS.LogParseException) LogEntryXML(com.cosylab.logging.engine.log.LogEntryXML) LogParseException(com.cosylab.logging.engine.ACS.LogParseException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) ILogEntry(com.cosylab.logging.engine.log.ILogEntry) LogEntry(com.cosylab.logging.engine.log.LogEntry) SAXException(org.xml.sax.SAXException)

Example 42 with ILogEntry

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;
}
Also used : LogParseException(com.cosylab.logging.engine.ACS.LogParseException) ILogEntry(com.cosylab.logging.engine.log.ILogEntry) LogEntry(com.cosylab.logging.engine.log.LogEntry) LogParseException(com.cosylab.logging.engine.ACS.LogParseException)

Example 43 with ILogEntry

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);
        }
    }
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry)

Example 44 with ILogEntry

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);
}
Also used : AdditionalData(com.cosylab.logging.engine.log.ILogEntry.AdditionalData) LogEngineException(com.cosylab.logging.engine.LogEngineException) ParseException(java.text.ParseException) ILogEntry(com.cosylab.logging.engine.log.ILogEntry) LogEntry(com.cosylab.logging.engine.log.LogEntry)

Example 45 with ILogEntry

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);
    }
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry)

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