Search in sources :

Example 81 with ILogEntry

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

the class ACSLogParserTest method testFields.

/**
	 * Check if the fields are read as expected
	 * 
	 * @throws Exception
	 */
public void testFields() throws Exception {
    // Cycle through all available parsers
    for (ParserTypes type : ParserTypes.values()) {
        System.out.println("testFields: Testing parser " + type);
        parser = ACSLogParserFactory.getParser(type);
        assertNotNull(parser);
        assertEquals(type, ACSLogParserFactory.getParserType(parser));
        ILogEntry log = parser.parse(xmlLogInfo1);
        assertNotNull(log);
        // Check the date
        Long logDate = (Long) log.getField(LogField.TIMESTAMP);
        assertNotNull(logDate);
        Long xmlDate = null;
        SimpleDateFormat dateFormat = new IsoDateFormat();
        Date date = dateFormat.parse("2006-03-28T00:26:29.238");
        xmlDate = Long.valueOf(date.getTime());
        assertEquals("The dates differ", xmlDate, logDate);
        // Check the log type
        assertEquals(LogTypeHelper.INFO, (LogTypeHelper) log.getField(LogField.ENTRYTYPE));
        // Check the file
        assertEquals("maciContainerImpl.cpp", log.getField(LogField.FILE));
        // Check the line
        assertEquals(Integer.valueOf(1454), log.getField(LogField.LINE));
        // Check the routine
        assertEquals("maci::ContainerImpl::initThread", log.getField(LogField.ROUTINE));
        // Check the host
        assertEquals("gas", log.getField(LogField.HOST));
        // Check the process
        assertEquals("maciContainer", log.getField(LogField.PROCESS));
        // Check the thread
        assertEquals("ARCHIVE_BULKSENDER::actionThread", log.getField(LogField.THREAD));
        // Check the Antenna
        assertEquals("CTXT", log.getField(LogField.CONTEXT));
        // Check the source object
        assertEquals("ARCHIVE_BULKSENDER::source", log.getField(LogField.SOURCEOBJECT));
        // Check the stack level
        assertEquals(10, log.getField(LogField.STACKLEVEL));
        // Check the stack level
        assertEquals(3, log.getField(LogField.PRIORITY));
        // Check the stack level
        assertEquals("TheStackID", log.getField(LogField.STACKID));
        // Check the Audience
        assertEquals("Operator", log.getField(LogField.AUDIENCE));
        // Check the Array
        assertEquals("AnArray", log.getField(LogField.ARRAY));
        // Check the Antenna
        assertEquals("ThisIsTheAntenna", log.getField(LogField.ANTENNA));
    }
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) ParserTypes(alma.acs.logging.engine.parser.ACSLogParserFactory.ParserTypes) IsoDateFormat(alma.acs.util.IsoDateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 82 with ILogEntry

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

the class CacheUtils method generateLogs.

/**
	 * Generate a set of logs to be used for testing
	 * Each log has 
	 *    - a different time stamp.
	 *    - the message contains the key of the log
	 *    - the log type is random (all types but Trace because trace
	 *      has no body)
	 *
	 * @param numOfLogs The number of logs to put in the collection
	 * @return The collection with the logs
	 */
public static Collection<ILogEntry> generateLogs(int numOfLogs) throws Exception {
    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("<");
        int typePos = rnd.nextInt(LogTypeHelper.values().length - 1);
        LogTypeHelper type = LogTypeHelper.values()[typePos];
        if (type == LogTypeHelper.TRACE) {
            type = LogTypeHelper.INFO;
        }
        logStr.append(type.logEntryType);
        logStr.append(logHeaderStr);
        logStr.append(dateSB.toString());
        logStr.append(logBodyStr);
        logStr.append(t);
        logStr.append(logFooterStr);
        logStr.append(type.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) LogTypeHelper(com.cosylab.logging.engine.log.LogTypeHelper) SimpleDateFormat(java.text.SimpleDateFormat) Vector(java.util.Vector)

Example 83 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 84 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 85 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)

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