Search in sources :

Example 16 with IsoDateFormat

use of alma.acs.util.IsoDateFormat in project ACS by ACS-Community.

the class LogProcessorTest method createLog.

private ILogEntry createLog(String logMsg) throws Exception {
    ACSLogParser parser = ACSLogParserFactory.getParser();
    long now = Calendar.getInstance().getTimeInMillis();
    SimpleDateFormat df = new IsoDateFormat();
    Date dt = new Date(now);
    StringBuffer dateSB = new StringBuffer();
    FieldPosition pos = new FieldPosition(0);
    df.format(dt, dateSB, pos);
    StringBuilder logStr = new StringBuilder("<Info TimeStamp=\"");
    logStr.append(dateSB.toString());
    logStr.append("\" Routine=\"CacheTest::testGet\" Host=\"this\" Process=\"test\" Thread=\"main\" Context=\"\"><![CDATA[");
    logStr.append(logMsg);
    logStr.append("]]></Info>");
    ILogEntry newLog = parser.parse(logStr.toString());
    return newLog;
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) ACSLogParser(alma.acs.logging.engine.parser.ACSLogParser) IsoDateFormat(alma.acs.util.IsoDateFormat) FieldPosition(java.text.FieldPosition) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 17 with IsoDateFormat

use of alma.acs.util.IsoDateFormat in project ACS by ACS-Community.

the class LogEntry method toString.

/**
	 * Return a string representation of this entry
	 */
public String toString() {
    StringBuffer sb = new StringBuffer("--- LogEntry ---\n");
    /* Attributes */
    for (LogField f : LogField.values()) {
        if (getField(f) != null) {
            sb.append(f.getName() + ": ");
            if (f == LogField.ENTRYTYPE) {
                sb.append(type.logEntryType);
            } else if (f == LogField.TIMESTAMP) {
                SimpleDateFormat df = new IsoDateFormat();
                FieldPosition pos = new FieldPosition(0);
                df.format(date, sb, pos);
            } else {
                sb.append(getField(f));
            }
            sb.append("\n");
        }
    }
    /* Data(s) */
    if (additionalData != null) {
        sb.append("Datas: \n");
        for (int t = 0; t < additionalData.size(); t++) {
            AdditionalData temp = additionalData.get(t);
            sb.append("\t" + temp.name + " : " + temp.value);
        }
    }
    return sb.toString();
}
Also used : IsoDateFormat(alma.acs.util.IsoDateFormat) FieldPosition(java.text.FieldPosition) SimpleDateFormat(java.text.SimpleDateFormat)

Example 18 with IsoDateFormat

use of alma.acs.util.IsoDateFormat in project ACS by ACS-Community.

the class EngineAudienceTest method testOperatorModeFiltering.

/**
	 * Test the filtering for OPERATOR.
	 * 
	 * The logs that should not be filtered are those that:
	 *  - have a level of WARINING or greater
	 *  - have the audience set to OPERATOR 
	 *  
	 *  The test is done in 2 times:
	 *   1. a collection of logs with no audience is tested
	 *   2. a collection of logs with different values for audience 
	 *      is tested
	 *  
	 * @throws Exception
	 */
public void testOperatorModeFiltering() throws Exception {
    audience = AudienceInfo.OPERATOR.getAudience();
    logRetieval.setAudience(audience);
    //
    // Step 1: generate a collection of logs with no audience
    //
    // Generate 1000 log of each type
    Collection<ILogEntry> logs = new Vector<ILogEntry>();
    for (LogTypeHelper logType : LogTypeHelper.values()) {
        if (logType != LogTypeHelper.OFF) {
            Collection<ILogEntry> tempLogs = CacheUtils.generateLogsType(1000, logType);
            logs.addAll(tempLogs);
        }
    }
    assertEquals(1000 * (LogTypeHelper.values().length - 1), logs.size());
    for (ILogEntry log : logs) {
        logRetieval.addLog(log.toXMLString());
    }
    // Wait until logRetrieval publish all the logs
    assertFalse("Timeout waiting for logs", waitForLogs());
    // Check the received logs
    assertEquals(logs.size(), numOfReceivedXMLLogs);
    assertEquals(1000 * 5, numOfReceivedLogs);
    // 
    // Step 2: test a collection of logs with the audience
    //
    ACSLogParser parser = ACSLogParserFactory.getParser();
    assertNotNull(parser);
    SimpleDateFormat df = new IsoDateFormat();
    assertNotNull(df);
    // Generate 2 logs for each type.
    // only one of them with audience OPERATOR
    logs.clear();
    for (LogTypeHelper logType : LogTypeHelper.values()) {
        if (logType == LogTypeHelper.OFF) {
            continue;
        }
        Date dt = new Date(System.currentTimeMillis());
        StringBuffer dateSB = new StringBuffer();
        FieldPosition pos = new FieldPosition(0);
        df.format(dt, dateSB, pos);
        StringBuilder logOperatorStr = new StringBuilder("<");
        StringBuilder logNoOperatorStr = new StringBuilder();
        // (see COMP-3749 : JDK levels FINER and FINEST were previously mapped to TRACE, while now FINER maps to DELOUSE).
        if (logType == LogTypeHelper.TRACE || logType == LogTypeHelper.DELOUSE) {
            logType = LogTypeHelper.INFO;
        }
        logOperatorStr.append(logType.logEntryType);
        logOperatorStr.append(logHeaderStr);
        logOperatorStr.append(dateSB.toString());
        logOperatorStr.append(logBodyStr);
        // Insert the audience
        logNoOperatorStr = new StringBuilder(logOperatorStr);
        logOperatorStr.append(alma.log_audience.OPERATOR.value);
        logNoOperatorStr.append(alma.log_audience.DEVELOPER.value);
        logOperatorStr.append(logEndOfBodyStr);
        logNoOperatorStr.append(logEndOfBodyStr);
        logOperatorStr.append("LOG Txt>");
        logNoOperatorStr.append("LOG Txt>");
        logOperatorStr.append(logFooterStr);
        logNoOperatorStr.append(logFooterStr);
        logOperatorStr.append(logType.logEntryType);
        logNoOperatorStr.append(logType.logEntryType);
        logOperatorStr.append('>');
        logNoOperatorStr.append('>');
        ILogEntry logOp = parser.parse(logOperatorStr.toString());
        logs.add(logOp);
        ILogEntry logNoOp = parser.parse(logNoOperatorStr.toString());
        logs.add(logNoOp);
    }
    assertEquals(2 * (LogTypeHelper.values().length - 1), logs.size());
    numOfReceivedLogs = 0;
    numOfReceivedXMLLogs = 0;
    for (ILogEntry log : logs) {
        logRetieval.addLog(log.toXMLString());
    }
    assertFalse("Timeout waiting for logs", waitForLogs());
    assertEquals(logs.size(), numOfReceivedXMLLogs);
    assertEquals(10, numOfReceivedLogs);
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) LogTypeHelper(com.cosylab.logging.engine.log.LogTypeHelper) ACSLogParser(alma.acs.logging.engine.parser.ACSLogParser) IsoDateFormat(alma.acs.util.IsoDateFormat) FieldPosition(java.text.FieldPosition) Vector(java.util.Vector) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 19 with IsoDateFormat

use of alma.acs.util.IsoDateFormat 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 20 with IsoDateFormat

use of alma.acs.util.IsoDateFormat 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)

Aggregations

IsoDateFormat (alma.acs.util.IsoDateFormat)21 Date (java.util.Date)20 SimpleDateFormat (java.text.SimpleDateFormat)15 FieldPosition (java.text.FieldPosition)10 ILogEntry (com.cosylab.logging.engine.log.ILogEntry)9 ACSLogParser (alma.acs.logging.engine.parser.ACSLogParser)5 IOException (java.io.IOException)3 Vector (java.util.Vector)3 FileHelper (alma.acs.logging.archive.zoom.FileHelper)2 LogField (com.cosylab.logging.engine.log.LogField)2 LogTypeHelper (com.cosylab.logging.engine.log.LogTypeHelper)2 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 Random (java.util.Random)2 ParserTypes (alma.acs.logging.engine.parser.ACSLogParserFactory.ParserTypes)1 DataItem (cl.utfsm.samplingSystemUI.core.DataItem)1 LogParseException (com.cosylab.logging.engine.ACS.LogParseException)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 JFileChooser (javax.swing.JFileChooser)1