Search in sources :

Example 51 with ILogEntry

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

the class CacheUtils method generateLogsType.

/**
	 * Generate a set of logs of a given type
	 * Each log has 
	 *    - a different time stamp.
	 *    - the message contains the key of the log
	 *
	 * @param numOfLogs The number of logs to put in the collection
	 * @return The collection with the logs
	 */
public static Collection<ILogEntry> generateLogsType(int numOfLogs, LogTypeHelper logType) throws Exception {
    if (logType == LogTypeHelper.OFF) {
        throw new IllegalArgumentException("Cannot publish logs with level OFF");
    }
    Random rnd = new Random(Calendar.getInstance().getTimeInMillis());
    // Yesterday
    long now = Calendar.getInstance().getTimeInMillis() - 1000 * 60 * 60 * 24;
    SimpleDateFormat df = new IsoDateFormat();
    Vector<ILogEntry> v = new Vector<ILogEntry>(numOfLogs);
    for (int t = 0; t < numOfLogs; t++) {
        Date dt = new Date(now + t * 1000);
        StringBuffer dateSB = new StringBuffer();
        FieldPosition pos = new FieldPosition(0);
        df.format(dt, dateSB, pos);
        StringBuilder logStr = new StringBuilder("<");
        if (logType == LogTypeHelper.TRACE) {
            logType = LogTypeHelper.INFO;
        }
        logStr.append(logType.logEntryType);
        logStr.append(logHeaderStr);
        logStr.append(dateSB.toString());
        logStr.append(logBodyStr);
        logStr.append(t);
        logStr.append(logFooterStr);
        logStr.append(logType.logEntryType);
        logStr.append('>');
        if (parser == null) {
            parser = ACSLogParserFactory.getParser();
        }
        ILogEntry log = parser.parse(logStr.toString());
        v.add(log);
    }
    return v;
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) IsoDateFormat(alma.acs.util.IsoDateFormat) FieldPosition(java.text.FieldPosition) Date(java.util.Date) Random(java.util.Random) SimpleDateFormat(java.text.SimpleDateFormat) Vector(java.util.Vector)

Example 52 with ILogEntry

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

the class LogEntryTest method testEmptyData.

/**
	 * This test tries to parse 2 logs with empty Data.
	 * The former has a <Data .../> tag
	 * The latter has a <Data ...></Data> tag
	 * Both of the test should fail
	 * 
	 * @throws Exception
	 */
public void testEmptyData() throws Exception {
    String xml1 = "<Trace TimeStamp=\"2002-11-07T15:13:00.012\" File=\"maciHeartbeatController.cpp\" Line=\"64\"><Data Name=\"DataName\"/></Trace>";
    String xml2 = "<Trace TimeStamp=\"2002-11-07T15:13:00.012\" File=\"maciHeartbeatController.cpp\" Line=\"64\"><Data Name=\"DataName\"></Data></Trace>";
    ILogEntry log1 = null;
    try {
        logparser.parse(xml1);
    } catch (Exception e) {
        log1 = null;
    }
    assertNull("The parser parsed a null Data: <Data.../>", log1);
    ILogEntry log2 = null;
    try {
        logparser.parse(xml2);
    } catch (Exception e) {
        log2 = null;
    }
    assertNull("The parser parsed a null Data: <Data...></Data>", log2);
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry)

Example 53 with ILogEntry

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

the class LogEntryTest method testLogEntryConst.

public void testLogEntryConst() throws Exception {
    //public LogEntryXML(Node log) throws DOMException
    String xmlString = log.toXMLString();
    ILogEntry log1 = logparser.parse(xmlString);
    String actual = log.toString();
    String expected = log1.toString();
    assertEquals("The two logs are not equal.", expected, actual);
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry)

Example 54 with ILogEntry

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

the class LogTableRowFilter method include.

/**
	 * Compare the entry with the filters.
	 * <P>
	 * The entry represents a row of the table and it is possible to get the
	 * values of all the cells of the row using an index.
	 * The order of the columns is independent of the way the appear in the table
	 * and therefore is like this:
	 * <OL>
	 *   <LI> - Boolean (has data)
	 *   <LI> - LogField.TIMESTAMP
	 *   <LI> - LogField.ENTRYTYPE
	 * 	 <LI> - ..
	 * </OL>
	 * <P>
	 * The filtering is done by getting the value to check against the filter from the column (index)
	 * containing it in <code>entry</code>. 
	 * It is possible to know which field a filter wants to filter by reading the <code>Filter.field</code>
	 * property.
	 * <P>Once we have the filter and the value to filter, we can use <code>filter.applyTo(Object obj)</code>
	 * method to check if the row matches the filter.
	 * 
	 * @param entry The entry to check against filters
	 * @return <code>true</code> if the entry passed the filters and must be displayed in the table
	 * @see RowFilter.include
	 */
@Override
public boolean include(Entry<? extends LogTableDataModel, ? extends Integer> entry) {
    // Check the log level
    if (!checkLogLevel((LogTypeHelper) entry.getValue(LogField.ENTRYTYPE.ordinal() + 1))) {
        return false;
    }
    // If there are no filters defined, the entry is accepted
    if (filters == null) {
        return true;
    }
    // Get the log to check against the filters
    LogTableDataModel model = entry.getModel();
    ILogEntry log = model.getVisibleLogEntry(entry.getIdentifier().intValue());
    // Check if the log matches with the filters
    boolean ret = true;
    for (int t = 0; t < filters.length && ret; t++) {
        ret = ret && filters[t].applyTo(log, false);
    }
    return ret;
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) LogTypeHelper(com.cosylab.logging.engine.log.LogTypeHelper)

Example 55 with ILogEntry

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

the class LogEntryTableModelBase method getVisibleLogEntry.

/**
	 * Return the log shown in the passed row.
	 * <P>
	 * This must be called inside the EDT.
	 * 
	 * @param row The row of the table containing the log
	 * @return The log in the passed row
	 */
public ILogEntry getVisibleLogEntry(int row) {
    if (closed) {
        return null;
    }
    try {
        ILogEntry ret;
        ret = allLogs.getLog(rows.get(row));
        return ret;
    } catch (LogCacheException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) LogCacheException(com.cosylab.logging.client.cache.LogCacheException)

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