Search in sources :

Example 11 with IsoDateFormat

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

the class FileHelperTest method testLoadTimelRange.

/**
	 * Test the loading of logs between a defined time interval
	 */
public void testLoadTimelRange() 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.values()[0], LogTypeHelper.values()[LogTypeHelper.values().length - 1]);
    numOfLogsRead = 0;
    assertTrue(fileHelper.loadLogs(this, this, this));
    assertEquals(45, numOfLogsRead);
}
Also used : FileHelper(alma.acs.logging.archive.zoom.FileHelper) IsoDateFormat(alma.acs.util.IsoDateFormat) Date(java.util.Date)

Example 12 with IsoDateFormat

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

the class AlarmTable method saveAlarm.

/**
	 * Save the alarm in a file
	 * 
	 * @param The alarm to save in a plain text file
	 */
public void saveAlarm(final Alarm alarm) {
    // Get the user dir property
    final JFileChooser fileChooser = new JFileChooser();
    if (fileChooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) {
        return;
    }
    // Save the file
    new Thread(new Runnable() {

        public void run() {
            // Build the text to write
            SimpleDateFormat dateFormat = new IsoDateFormat();
            StringBuilder str = new StringBuilder(alarm.toString());
            str.append("\n\n");
            str.append("Saved at ");
            str.append(dateFormat.format(new Date(System.currentTimeMillis())));
            str.append("\n\n");
            // Save the file
            File outF = fileChooser.getSelectedFile();
            FileOutputStream fOutS;
            try {
                fOutS = new FileOutputStream(outF, false);
                fOutS.write(str.toString().getBytes());
                fOutS.flush();
                fOutS.close();
            } catch (Exception e) {
                JOptionPane.showInternalMessageDialog(AlarmTable.this, e.getMessage(), "Error saving", JOptionPane.ERROR_MESSAGE);
            }
        }
    }, "SaveThread").start();
}
Also used : JFileChooser(javax.swing.JFileChooser) FileOutputStream(java.io.FileOutputStream) IsoDateFormat(alma.acs.util.IsoDateFormat) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) Date(java.util.Date)

Example 13 with IsoDateFormat

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

the class SearchEngine method find.

/**
     * The method executes the search for both the public overloaded 
     * find methods.
     * 
     * @param regExp The regular expression to look for in the logs
     *               null if the method search for a string 
     * @param searchString The string to look for in the logs
     *                     null if the method search for a reg exp
     * @param caseSensitive If true performs a CaseSensitive search
     *                      Ignored for reg exp searchs (it is coded
     *                      in the Pattern)
     * @param wholeWord If true look for the whole word int the column
     *                  Ignored for reg exp searchs
     * @param forwardSearch If true search forward otherwise backward
     * @param cols The columns of each log tool for the string
     * @return -1 if no log is found otherwise the row containing the string/reg exp
     */
private int find(Pattern regExp, String searchString, boolean caseSensitive, boolean wholeWord, boolean forwardSearch, boolean[] cols) {
    // I want only one loop for both forward and backward searches
    // For that I calculate the interval of valid rows to scan
    // [a,b] where a<=b i.e. this interval is independedent from the
    // direction of the search
    // Then I use a cursor to navigate the rows, decreasing or 
    // increasing its value depending of the direction of the search
    // Get the starting and the ending row for the search
    int startingRow = getStartingRow(forwardSearch);
    int endRow = (forwardSearch) ? logEntryTable.getRowCount() - 1 : 0;
    // The position where the SimpleDate must be written
    FieldPosition pos = new java.text.FieldPosition(0);
    // A temporary buffer
    StringBuffer tempSB = new StringBuffer();
    // The variable used to browse the rows
    int cursor = startingRow;
    // Order end and start rown in growing order 
    if (endRow < startingRow) {
        int temp = startingRow;
        startingRow = endRow;
        endRow = temp;
    }
    int foundRow = -1;
    while (cursor >= startingRow && cursor <= endRow && foundRow == -1) {
        // cols contains one entry for each field of a log entry
        // plus one entry for the additional data
        ILogEntry log = logTableDataModel.getVisibleLogEntry(logEntryTable.convertRowIndexToModel(cursor));
        // The value of the field
        String string = null;
        for (int t = 0; t < cols.length - 1; t++) {
            Object obj = log.getField(LogField.values()[t]);
            if (obj == null) {
                continue;
            }
            if (cols[t]) {
                switch(LogField.values()[t]) {
                    case TIMESTAMP:
                        {
                            SimpleDateFormat df = new IsoDateFormat();
                            Date dt = new Date((Long) obj);
                            tempSB.delete(0, tempSB.length());
                            df.format(dt, tempSB, pos);
                            string = tempSB.toString();
                            break;
                        }
                    case ENTRYTYPE:
                    case LINE:
                    case PRIORITY:
                    case STACKLEVEL:
                        {
                            string = obj.toString();
                            break;
                        }
                    default:
                        {
                            string = obj.toString();
                            break;
                        }
                }
                if (matches(string, regExp, searchString, caseSensitive, wholeWord)) {
                    if ((forwardSearch && cursor != startingRow) || (!forwardSearch && cursor != endRow)) {
                        foundRow = cursor;
                        if (forwardSearch) {
                            cursor++;
                        } else {
                            cursor--;
                        }
                        return foundRow;
                    }
                }
            }
        }
        // searching for regular espressions
        if (cols[cols.length - 1] && log.hasDatas()) {
            Vector<ILogEntry.AdditionalData> addData = log.getAdditionalData();
            for (int t = 0; t < addData.size(); t++) {
                ILogEntry.AdditionalData data = addData.elementAt(t);
                string = data.name;
                if (matches(string, regExp, searchString, caseSensitive, wholeWord)) {
                    if ((forwardSearch && cursor != startingRow) || (!forwardSearch && cursor != endRow)) {
                        foundRow = cursor;
                        if (forwardSearch) {
                            cursor++;
                        } else {
                            cursor--;
                        }
                        return foundRow;
                    }
                }
                string = data.value;
                if (matches(string, regExp, searchString, caseSensitive, wholeWord)) {
                    if ((forwardSearch && cursor != startingRow) || (!forwardSearch && cursor != endRow)) {
                        foundRow = cursor;
                        if (forwardSearch) {
                            cursor++;
                        } else {
                            cursor--;
                        }
                        return foundRow;
                    }
                }
            }
        }
        if (forwardSearch) {
            cursor++;
        } else {
            cursor--;
        }
    }
    return foundRow;
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) FieldPosition(java.text.FieldPosition) IsoDateFormat(alma.acs.util.IsoDateFormat) Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat)

Example 14 with IsoDateFormat

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

the class AntennaSourceReductionTest method createLog.

/**
	 * Create a log entry with the passed message and source
	 * 
	 * @param logMsg The message
	 * @param logSrc The source
	 * @return The log entry
	 * @throws Exception
	 */
private ILogEntry createLog(String logMsg, String logSrc) 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\" SourceObject=\"");
    logStr.append(logSrc);
    logStr.append("\" 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 15 with IsoDateFormat

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

the class AntennaReductionTest 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)

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