Search in sources :

Example 61 with ILogEntry

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

the class CacheTest method testAddLog.

/**
	 * Check the add method by inserting and reading a log
	 *
	 */
public void testAddLog() throws Exception {
    ACSLogParser parser = ACSLogParserFactory.getParser();
    int oldSize = cache.getSize();
    String logMsg = "Test log";
    String logStr = "<Info TimeStamp=\"2005-11-29T15:33:10.592\" Routine=\"CacheTest::testGet\" Host=\"this\" Process=\"test\" Thread=\"main\" Context=\"\"><![CDATA[" + logMsg + "]]></Info>";
    ILogEntry newLog = parser.parse(logStr);
    cache.add(newLog);
    assertEquals("Error adding a log", cache.getSize(), oldSize + 1);
    ILogEntry log = cache.getLog(cache.getSize() - 1);
    String msg = (String) log.getField(LogField.LOGMESSAGE);
    assertEquals("Error adding a log", logMsg, msg);
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) ACSLogParser(alma.acs.logging.engine.parser.ACSLogParser)

Example 62 with ILogEntry

use of com.cosylab.logging.engine.log.ILogEntry 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)

Example 63 with ILogEntry

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

the class ErrorTab method initialize.

/**
	 * Init the GUI
	 */
private void initialize() {
    // Init the table
    table.createDefaultColumnsFromModel();
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setAutoCreateRowSorter(true);
    TableColumnModel tcm = table.getColumnModel();
    TableColumn tc;
    // Setup the first col 
    tc = tcm.getColumn(0);
    tc.setCellRenderer(new InfoRenderer());
    tc.setWidth(18);
    tc.setMaxWidth(18);
    tc.setResizable(false);
    tc = tcm.getColumn(LogField.ENTRYTYPE.ordinal() + 1);
    tc.setCellRenderer(new EntryTypeRenderer(false));
    tc = tcm.getColumn(LogField.TIMESTAMP.ordinal() + 1);
    tc.setCellRenderer(new DateRenderer(true));
    for (int t = 1; t < tcm.getColumnCount(); t++) {
        tc = tcm.getColumn(t);
        tc.setMinWidth(50);
        tc.setPreferredWidth(100);
        tc.setResizable(true);
        tc.setIdentifier(LogField.values()[t - 1]);
        columns[t - 1] = tc;
    }
    // Set the visible columns
    boolean[] visCols = new boolean[LogField.values().length];
    for (int t = 0; t < visCols.length; t++) {
        visCols[t] = false;
    }
    visCols[LogField.TIMESTAMP.ordinal()] = true;
    visCols[LogField.ENTRYTYPE.ordinal()] = true;
    visCols[LogField.SOURCEOBJECT.ordinal()] = true;
    visCols[LogField.LOGMESSAGE.ordinal()] = true;
    visCols[LogField.STACKLEVEL.ordinal()] = true;
    setupTableCols(visCols);
    // Add the tabs
    setRightComponent(new JScrollPane(detailedLogTable));
    setLeftComponent(new JScrollPane(table));
    setDividerLocation(table.getPreferredSize().width);
    // Init the popup menu
    JMenuItem menuItem = new JMenuItem("Select columns...");
    menuItem.addActionListener(this);
    popmenu = new JPopupMenu();
    popmenu.add(menuItem);
    // Add the listener to the table header
    table.getTableHeader().addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                popmenu.show(ErrorTab.this.table, e.getX(), e.getY());
            }
        }
    });
    // Add the listener to the table
    table.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent e) {
            if (!e.isPopupTrigger()) {
                // Get the index of the row and the column below
                // the mouse pointer
                int row = ErrorTab.this.table.rowAtPoint(e.getPoint());
                ILogEntry log = model.getVisibleLogEntry(table.convertRowIndexToModel(row));
                ErrorTab.this.detailedLogTable.setupContent(log);
            }
        }
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) ILogEntry(com.cosylab.logging.engine.log.ILogEntry) InfoRenderer(alma.acs.logging.table.renderer.InfoRenderer) MouseAdapter(java.awt.event.MouseAdapter) TableColumnModel(javax.swing.table.TableColumnModel) DateRenderer(alma.acs.logging.table.renderer.DateRenderer) TableColumn(javax.swing.table.TableColumn) JPopupMenu(javax.swing.JPopupMenu) EntryTypeRenderer(alma.acs.logging.table.renderer.EntryTypeRenderer) JMenuItem(javax.swing.JMenuItem)

Example 64 with ILogEntry

use of com.cosylab.logging.engine.log.ILogEntry 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 65 with ILogEntry

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

the class LogFileCache method fromCacheString.

private ILogEntry fromCacheString(String str) {
    String[] strs = str.split(SEPARATOR);
    Long millis = new Long(strs[0]);
    Integer entrytype = new Integer(strs[1]);
    String srcObject = null;
    if (strs.length > 2) {
        srcObject = strs[2];
    }
    String fileNM = null;
    if (strs.length > 3) {
        fileNM = strs[3];
    }
    Integer line = null;
    if (strs.length > 4 && strs[4].length() != 0) {
        line = new Integer(strs[4]);
    }
    String routine = null;
    if (strs.length > 5) {
        routine = strs[5];
    }
    String host = null;
    if (strs.length > 6) {
        host = strs[6];
    }
    String process = null;
    if (strs.length > 7) {
        process = strs[7];
    }
    String context = null;
    if (strs.length > 8) {
        context = strs[8];
    }
    String thread = null;
    if (strs.length > 9) {
        thread = strs[9];
    }
    String logid = null;
    if (strs.length > 10) {
        logid = strs[10];
    }
    Integer priority = null;
    if (strs.length > 11 && strs[11].length() > 0) {
        priority = new Integer(strs[11]);
    }
    String uri = null;
    if (strs.length > 12) {
        uri = strs[12];
    }
    String stackid = null;
    if (strs.length > 13) {
        stackid = strs[13];
    }
    Integer stacklevel = null;
    if (strs.length > 14 && strs[14].length() > 0) {
        stacklevel = Integer.parseInt(strs[14]);
    }
    String logmessage = null;
    if (strs.length > 15) {
        logmessage = strs[15];
    }
    String audience = null;
    if (strs.length > 16) {
        audience = strs[16];
    }
    String array = null;
    if (strs.length > 17) {
        array = strs[17];
    }
    String antenna = null;
    if (strs.length > 18) {
        antenna = strs[18];
    }
    Vector<ILogEntry.AdditionalData> addDatas = null;
    if (strs.length > LogField.values().length) {
        addDatas = new Vector<ILogEntry.AdditionalData>();
        for (int t = LogField.values().length; t < strs.length; t += 2) {
            addDatas.add(new AdditionalData(strs[t], strs[t + 1]));
        }
    }
    return new LogEntry(millis, entrytype, fileNM, line, routine, host, process, context, thread, logid, priority, uri, stackid, stacklevel, logmessage, srcObject, audience, array, antenna, addDatas);
}
Also used : AdditionalData(com.cosylab.logging.engine.log.ILogEntry.AdditionalData) ILogEntry(com.cosylab.logging.engine.log.ILogEntry) LogEntry(com.cosylab.logging.engine.log.LogEntry)

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