Search in sources :

Example 1 with LogMatcher

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

the class QueryDlg method submitQuery.

/**
	 * Submit a query to the archive and insert the logs in the main window
	 *
	 */
private void submitQuery() {
    FieldState chekResult = checkFields();
    if (chekResult != FieldState.OK) {
        JOptionPane.showMessageDialog(this, "<HTML>Error getting values from the form!<BR>Check the values of " + chekResult.desc, "Input error!", JOptionPane.ERROR_MESSAGE);
        return;
    }
    loggingClient.reportStatus("Submitting a query");
    // Clear the logs and disconnect from the NC
    guiSwitches.execute();
    StringBuilder from = new StringBuilder(fromYY.getText());
    from.append('-');
    if (fromMM.getText().length() == 1) {
        from.append('0');
    }
    from.append(fromMM.getText());
    from.append('-');
    if (fromDD.getText().length() == 1) {
        from.append('0');
    }
    from.append(fromDD.getText());
    from.append('T');
    if (fromHr.getText().length() == 1) {
        from.append('0');
    }
    from.append(fromHr.getText());
    from.append(':');
    if (fromMin.getText().length() == 1) {
        from.append('0');
    }
    from.append(fromMin.getText());
    from.append(':');
    if (fromSec.getText().length() == 1) {
        from.append('0');
    }
    from.append(fromSec.getText());
    StringBuilder to = new StringBuilder(toYY.getText());
    to.append('-');
    if (toMM.getText().length() == 1) {
        to.append('0');
    }
    to.append(toMM.getText());
    to.append('-');
    if (toDD.getText().length() == 1) {
        to.append('0');
    }
    to.append(toDD.getText());
    to.append('T');
    if (toHr.getText().length() == 1) {
        to.append('0');
    }
    to.append(toHr.getText());
    to.append(':');
    if (toMin.getText().length() == 1) {
        to.append('0');
    }
    to.append(toMin.getText());
    to.append(':');
    if (toSec.getText().length() == 1) {
        to.append('0');
    }
    to.append(toSec.getText());
    short minType = (short) LogTypeHelper.values()[minLogLevelCB.getSelectedIndex()].acsCoreLevel.value;
    short maxType = (short) LogTypeHelper.values()[maxLogLevelCB.getSelectedIndex()].acsCoreLevel.value;
    String routine = routineName.getText();
    if (routine.length() == 0) {
        routine = "*";
    }
    String source = sourceName.getText();
    if (source.length() == 0) {
        source = "*";
    }
    String process = procName.getText();
    if (process.length() == 0) {
        process = "*";
    }
    int maxRows = Integer.parseInt(rowLimit.getText());
    // The collection where the logs read from the DB are stored
    Collection logs = null;
    updateStatusLbl("Submitting query");
    try {
        logs = archive.getLogs(from.toString() + ".000", to.toString() + ".000", minType, maxType, routine, source, process, maxRows);
    } catch (Throwable t) {
        System.err.println("Error executing the query: " + t.getMessage());
        t.printStackTrace(System.err);
        JOptionPane.showMessageDialog(this, formatErrorMsg("Error executing the query:\n" + t.getMessage()), "Database error!", JOptionPane.ERROR_MESSAGE);
        loggingClient.reportStatus("Query terminated with error");
    }
    if (logs != null && !logs.isEmpty()) {
        loggingClient.reportStatus("Num. of logs read from DB: " + logs.size());
        LogMatcher matcher = new LogMatcher();
        matcher.setAudience(loggingClient.getEngine().getAudience());
        matcher.setFilters(loggingClient.getEngine().getFilters());
        matcher.setDiscardLevel(loggingClient.getEngine().getDiscardLevel());
        Iterator iter = logs.iterator();
        int count = 0;
        while (iter.hasNext() && !terminateThread) {
            if ((++count) % 1000 == 0) {
                updateStatusLbl("Flushing logs " + count + "/" + logs.size());
            }
            String str = (String) iter.next();
            ILogEntry logEntry = null;
            try {
                logEntry = parser.parse(str);
            } catch (Exception e) {
                errorListener.errorReceived(str);
                continue;
            }
            if (matcher.match(logEntry)) {
                logListener.logEntryReceived(logEntry);
            }
        }
        logs.clear();
        logs = null;
    }
    updateStatusLbl("");
    // Update the state of the switches
    guiSwitches.checkControlsState();
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) LogMatcher(com.cosylab.logging.engine.LogMatcher) Iterator(java.util.Iterator) Collection(java.util.Collection) Point(java.awt.Point) BadLocationException(javax.swing.text.BadLocationException)

Aggregations

LogMatcher (com.cosylab.logging.engine.LogMatcher)1 ILogEntry (com.cosylab.logging.engine.log.ILogEntry)1 Point (java.awt.Point)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 BadLocationException (javax.swing.text.BadLocationException)1