Search in sources :

Example 1 with ILogEntry

use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.

the class LogCache method getLog.

/**
	 * Return the log with the given key.
	 * The method is synchronized because both the HashMap and
	 * the LinkedList must be synchronized if there is a chance
	 * to acces these objects from more then one thread in the same 
	 * time
	 * @see java.util.LinkedList
	 * @see java.util.HashMap
	 *  
	 * @param pos The key of the log
	 * @return The LogEntryXML or null in case of error
	 */
public synchronized ILogEntry getLog(Integer key) throws LogCacheException {
    ILogEntry log;
    log = cache.get(key);
    if (log != null) {
        // Hit! The log is in the cache
        return log;
    } else {
        // Oops we need to read a log from disk!
        return loadNewLog(key);
    }
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry)

Example 2 with ILogEntry

use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.

the class LogCache method loadNewLog.

/**
	 * Get a log from the cache on disk updating all the 
	 * internal lists
	 * 
	 * @param idx The position of the log
	 * @return The log read from the cache on disk
	 */
private synchronized ILogEntry loadNewLog(Integer idx) throws LogCacheException {
    // Read the new log from the cache on disk
    ILogEntry log = super.getLog(idx);
    // There is enough room in the lists?
    if (cache.size() == actualCacheSize) {
        // We need to create a room for the new element
        Integer itemToRemove = manager.removeFirst();
        cache.remove(itemToRemove);
    }
    // Add the log in the cache
    cache.put(idx, log);
    // Append the index in the manager list
    manager.addLast(idx);
    return log;
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry)

Example 3 with ILogEntry

use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.

the class LogReceiver method startCaptureLogs.

/**
     * Variant of {@link #startCaptureLogs(PrintWriter)} which takes an optional ThreadFactory
     * which will be used to create the thread that reads out the log queue.
     * This method could be used if <code>LogReceiver</code> is run inside a container 
     * or as part of a ComponentClientTestCase.
	 */
public void startCaptureLogs(final PrintWriter logWriter, ThreadFactory threadFactory) throws IOException {
    if (!isInitialized()) {
        throw new IllegalStateException("First call LogReceiver#initialize(ORB, Manager), then startCaptureLogs(PrintWriter)");
    }
    if (listenForLogs) {
        if (verbose) {
            System.out.println("Ignoring call to 'startCaptureLogs' while already capturing logs.");
        }
        return;
    }
    Runnable logRetriever = new Runnable() {

        public void run() {
            //            	System.out.println("logRetriever.run called...");
            try {
                BlockingQueue<DelayedLogEntry> logQueue = getLogQueue();
                listenForLogs = true;
                // loop until "queue poison" entry is found
                while (true) {
                    try {
                        // extract logs from queue
                        DelayedLogEntry delayedLogEntry = logQueue.take();
                        if (delayedLogEntry.isQueuePoison()) {
                            if (verbose) {
                                System.out.println("got queue poison, will terminate method 'startCaptureLogs'.");
                            }
                            break;
                        } else {
                            ILogEntry logEntry = delayedLogEntry.getLogEntry();
                            String xmlLog = logEntry.toXMLString();
                            //								System.out.println("Yeah, got a log record: " + xmlLog);
                            logWriter.println(xmlLog);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            } catch (Throwable thr) {
                System.out.println("Log receiver got exception " + thr);
                logWriter.println("Log receiver failed with exception " + thr.toString());
            } finally {
                logWriter.close();
                // we only call stop now, so that late arriving records could still be added 
                // to the queue during the whole waiting time.
                stop();
            }
        }
    };
    Thread t = null;
    if (threadFactory != null) {
        t = threadFactory.newThread(logRetriever);
    } else {
        t = new Thread(logRetriever);
        t.setDaemon(true);
    }
    t.start();
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) LogEngineException(com.cosylab.logging.engine.LogEngineException) IOException(java.io.IOException)

Example 4 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 5 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)

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