Search in sources :

Example 6 with IsoDateFormat

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

the class LogEntry method toXMLString.

/**
	 * @return an XML string representing this log
	 */
public String toXMLString() {
    StringBuilder sb = new StringBuilder();
    String logType = type.logEntryType;
    sb.append("<" + logType);
    for (LogField t : LogField.values()) {
        if (t == LogField.LOGMESSAGE || t == LogField.ENTRYTYPE) {
            continue;
        }
        Object attrValue = getField(t);
        if (attrValue != null) {
            if (t == LogField.TIMESTAMP) {
                SimpleDateFormat df = new IsoDateFormat();
                Date dt = new Date((Long) attrValue);
                StringBuffer dateSB = new StringBuffer();
                java.text.FieldPosition pos = new java.text.FieldPosition(0);
                df.format(dt, dateSB, pos);
                attrValue = dateSB.toString();
            }
            String attrValStr = attrValue.toString();
            attrValStr = attrValStr.replaceAll("<", "&lt;");
            attrValStr = attrValStr.replaceAll(">", "&gt;");
            sb.append(" " + t.getTagAttribute() + "=\"" + attrValStr + "\"");
        }
    }
    if (type == LogTypeHelper.TRACE && !hasDatas() && logMessage != null && logMessage.trim().isEmpty()) {
        sb.append("/>");
    } else {
        sb.append(">");
        if (logMessage != null) {
            sb.append("<![CDATA[" + logMessage + "]]>");
        }
        if (hasDatas()) {
            sb.append(getXMLDatas());
        }
        sb.append("</" + logType + ">");
    }
    return sb.toString();
}
Also used : FieldPosition(java.text.FieldPosition) IsoDateFormat(alma.acs.util.IsoDateFormat) FieldPosition(java.text.FieldPosition) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 7 with IsoDateFormat

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

the class LogEntryTable method getCellStringContent.

/**
	 * Get a string representing the content of a cell
	 * 
	 * @param row The table row of the cell
	 * @param col The table column of the cell
	 * 
	 * @return A string representing the content of the cell
	 */
private String getCellStringContent(int row, int col) {
    Object value = getValueAt(row, col);
    if (value == null) {
        return "";
    }
    String tempStr = "";
    if (value instanceof Date) {
        IsoDateFormat sdf = new IsoDateFormat();
        tempStr = sdf.format(value);
    } else if (value instanceof Integer) {
        if (getColumnName(col).compareTo(LogField.ENTRYTYPE.getName()) == 0) {
            tempStr = LogTypeHelper.values()[((Integer) value).intValue()].logEntryType;
        } else {
            tempStr = value.toString();
        }
    } else {
        tempStr = value.toString();
    }
    return tempStr;
}
Also used : IsoDateFormat(alma.acs.util.IsoDateFormat) Date(java.util.Date)

Example 8 with IsoDateFormat

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

the class CSVConverter method convert.

/**
	 * Convert a log in a CSV string 
	 * 
	 * @param log The log to convert
	 * @return The CSV string representing the log
	 */
public String convert(ILogEntry log) {
    if (log == null) {
        throw new IllegalArgumentException("Impossible to convert a null log");
    }
    StringBuilder str = new StringBuilder();
    SimpleDateFormat df = new IsoDateFormat();
    for (int t = 0; t < colIndex.length(); t++) {
        if (t > 0) {
            str.append(separator);
        }
        Character c = Character.toUpperCase(colIndex.charAt(t));
        if ((c >= '0' && c <= '9') || (c >= 'A' && c <= Character.toUpperCase(LogField.values()[LogField.values().length - 1].id))) {
            LogField field = LogField.fromID(c);
            Object obj = log.getField(field);
            if (obj == null) {
                appendField(null, str);
            } else if (field == LogField.TIMESTAMP) {
                // Write the date in the right format
                Date dt = new Date(((Long) obj).longValue());
                StringBuffer dateSB = new StringBuffer();
                java.text.FieldPosition pos = new java.text.FieldPosition(0);
                df.format(dt, dateSB, pos);
                appendField(dateSB.toString(), str);
            } else if (field == LogField.ENTRYTYPE) {
                appendField(LogTypeHelper.fromLogTypeDescription(obj.toString()).logEntryType, str);
            } else {
                appendField(obj.toString(), str);
            }
        } else {
            // DATA
            if (log.hasDatas()) {
                appendField(formatData(log.getAdditionalData()), str);
            } else {
                appendField(null, str);
            }
        }
    }
    str.append('\n');
    return str.toString();
}
Also used : IsoDateFormat(alma.acs.util.IsoDateFormat) LogField(com.cosylab.logging.engine.log.LogField) Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat)

Example 9 with IsoDateFormat

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

the class FileHelperTest method testLoadFilterAll.

/**
	 * Test the loading of logs between a defined time interval
	 * and a definit log level interval
	 */
public void testLoadFilterAll() throws Exception {
    IsoDateFormat dateFormat = new IsoDateFormat();
    Date startDate = dateFormat.parse("2008-09-19T11:21:49.500");
    Date endDate = dateFormat.parse("2008-09-19T11:21:49.600");
    fileHelper = new FileHelper(testFile, startDate.getTime(), endDate.getTime(), LogTypeHelper.DEBUG, LogTypeHelper.NOTICE);
    numOfLogsRead = 0;
    assertTrue(fileHelper.loadLogs(this, this, this));
    assertEquals(15, numOfLogsRead);
}
Also used : FileHelper(alma.acs.logging.archive.zoom.FileHelper) IsoDateFormat(alma.acs.util.IsoDateFormat) Date(java.util.Date)

Example 10 with IsoDateFormat

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

the class CacheTest method fillCache.

/**
	 * Fill the cache with dynamically generated logs
	 * The number of logs inserted in the list is greater than the 
	 * memory cache size to stress the disk cache also.
	 * 
	 * @return The number of logs inserted in the cache
	 * 
	 * @throws Exception
	 */
private long fillCache() throws Exception {
    ACSLogParser parser = ACSLogParserFactory.getParser();
    String logMsg = "Test log nr. ";
    // Yesterday
    long now = Calendar.getInstance().getTimeInMillis() - 1000 * 60 * 60 * 24;
    SimpleDateFormat df = new IsoDateFormat();
    cache.clear();
    long logToInsert = 2 * cache.getCacheSize();
    for (int t = 0; t < logToInsert; t++) {
        Date dt = new Date(now + t * 1000);
        StringBuffer dateSB = new StringBuffer();
        FieldPosition pos = new FieldPosition(0);
        df.format(dt, dateSB, pos);
        String newLogMsg = logMsg + "t";
        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(newLogMsg);
        logStr.append("]]></Info>");
        ILogEntry newLog = parser.parse(logStr.toString());
        cache.add(newLog);
    }
    return logToInsert;
}
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)

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