Search in sources :

Example 1 with LogTypeHelper

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

the class LogFrame method main.

/**
	 * Starts the application.
	 * @param args an array of command-line arguments
	 */
public static void main(java.lang.String[] args) {
    // Parse the command line
    CommandLineParser parser = null;
    try {
        parser = new CommandLineParser(args);
    } catch (Throwable t) {
        CommandLineParser.printUsage(t.getMessage());
        System.exit(-1);
    }
    if (parser.getHelp()) {
        CommandLineParser.printUsage(null);
        return;
    }
    /** 
		 * If it is not <code>null</code> then the user specified a file name in the
		 * command line
		 */
    String initLogFileName = parser.getFileToLoad();
    /** 
		 * If it is not <code>null</code> then the user specified a filter file name in the
		 * command line
		 */
    String initFilterFileName = parser.getFilterFileName();
    /** 
		 * If it is not <code>null</code> then the user specified an engine  filter 
		 * file name in the command line
		 */
    String initEngineFilterFileName = parser.getEngineFilterFileName();
    /**
		 *  <code>true</code> if the user do not want the logging client tries to connect to ACS 
		 *  at startup
		 */
    boolean doNotConnect = parser.isDoNotConnect();
    /**
		 * <code>true</code> if the user does not want to limit the number of logs to  keep in memory
		 */
    boolean unlimited = parser.isUnlimited();
    /**
		 * The audience set in the command line.
		 * <P>
		 * <code>null</code> if the user did not set the audience in the
		 * command line. 
		 */
    AudienceInfo audienceInfo = parser.getAudience();
    /**
		 * The initial discard level.
		 * If it not set in the command line, the logging client starts
		 * with the default discard level
		 */
    LogTypeHelper initialDiscardLevel = parser.getDiscardLevel();
    File logFile = null;
    if (initLogFileName != null) {
        // Check if the file in the cmd line is readable
        logFile = new File(initLogFileName);
        if (!logFile.exists()) {
            System.err.println("log file " + initLogFileName + " does not exist!");
            initLogFileName = null;
            System.exit(-1);
        }
        if (!logFile.canRead()) {
            System.err.println("log file " + initLogFileName + " is unreadable!");
            initLogFileName = null;
            System.exit(-1);
        }
    }
    File filterFile = null;
    if (initFilterFileName != null) {
        filterFile = new File(initFilterFileName);
        if (!filterFile.canRead()) {
            System.err.println("Filter file " + initFilterFileName + " is unreadable!");
            System.exit(-1);
        }
    }
    File engineFilterFile = null;
    if (initEngineFilterFileName != null) {
        engineFilterFile = new File(initEngineFilterFileName);
        if (!engineFilterFile.canRead()) {
            System.err.println("Filter file " + initFilterFileName + " is unreadable!");
            System.exit(-1);
        }
    }
    try {
        // Create the frame
        class FrameLauncher extends Thread {

            private final File f;

            private final File ef;

            private final String name;

            private final boolean offline;

            private final LogTypeHelper discard;

            private final boolean noLimit;

            private final AudienceInfo aInfo;

            public FrameLauncher(File fltFile, File engfltFile, String initFileName, LogTypeHelper initDiscard, boolean noACS, boolean unlimit, AudienceInfo info) {
                f = fltFile;
                ef = engfltFile;
                name = initFileName;
                discard = initDiscard;
                offline = noACS;
                noLimit = unlimit;
                aInfo = info;
            }

            public void run() {
                new LogFrame(f, ef, name, discard, offline, noLimit, aInfo);
            }
        }
        SwingUtilities.invokeLater(new FrameLauncher(filterFile, engineFilterFile, initLogFileName, initialDiscardLevel, doNotConnect, unlimited, audienceInfo));
    } catch (Throwable exception) {
        System.err.println("Exception occurred in main() of LoggingFrame");
        exception.printStackTrace(System.err);
    }
}
Also used : LogTypeHelper(com.cosylab.logging.engine.log.LogTypeHelper) AudienceInfo(com.cosylab.logging.engine.audience.Audience.AudienceInfo) File(java.io.File)

Example 2 with LogTypeHelper

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

the class LogToolBar method getLogLevelCB.

/**
     * 
     * @return The log level CB
     */
public JComboBox getLogLevelCB() {
    if (logLevelCB == null) {
        // Add the ComboBox for the log level
        LogTypeHelper[] types = LogTypeHelper.values();
        int t = 0;
        //    		for (LogTypeHelper logType: LogTypeHelper.values()) {
        //    			Descriptions[t++]=logType.logEntryType;
        //            }
        logLevelCB = new JComboBox(types);
        // Build the renderer for the combo boxes
        LogTypeRenderer rendererCB = new LogTypeRenderer();
        logLevelCB.setSelectedItem(initialLogLevel);
        logLevelCB.setEditable(false);
        logLevelCB.setMaximumRowCount(LogTypeHelper.values().length);
        logLevelCB.setRenderer(rendererCB);
    }
    return logLevelCB;
}
Also used : JComboBox(javax.swing.JComboBox) LogTypeRenderer(com.cosylab.logging.settings.LogTypeRenderer) LogTypeHelper(com.cosylab.logging.engine.log.LogTypeHelper)

Example 3 with LogTypeHelper

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

the class Filter method buildFilter.

/**
	 * Build a Filter object All the parameters are String objects. Before
	 * building the object, the value of each parameter is checked This method
	 * is too long (and boring) for my taste but it is very easy
	 * 
	 * @param type The type of filter to build
	 * @param field The filed parameter fo Filter
	 * @param lethal The isLethal parameter of Filter
	 * @param not The applyAsNOT parameter of Filter
	 * @param min The minimum parameter of Filter
	 * @param minType The type of minimum
	 * @param max The max parameter of Filter
	 * @param maxType The type of max
	 * @param exact The exact parameter of Filter
	 * @param exactType The type of exact
	 * @param wildChar The regularExpression parameter of Filter
	 * @return The Filter object built or null if an error occurred decoding the
	 *         parameters
	 * @throws Exception in case of error building the filter
	 */
public static Filter buildFilter(Constraint type, LogField field, String lethal, String not, String min, String minType, String max, String maxType, String exact, String exactType, String wildChar) throws Exception {
    // Trim all the strings
    if (lethal != null) {
        lethal = lethal.trim();
    }
    if (not != null) {
        not = not.trim();
    }
    if (min != null) {
        min = min.trim();
    }
    if (minType != null) {
        minType = minType.trim();
    }
    if (max != null) {
        max = max.trim();
    }
    if (maxType != null) {
        maxType = maxType.trim();
    }
    if (exact != null) {
        exact = exact.trim();
    }
    if (exactType != null) {
        exactType = exactType.trim();
    }
    if (wildChar != null) {
        wildChar = wildChar.trim();
    }
    // Read the int from field
    if (field == null) {
        throw new IllegalArgumentException("Parameter field can't be null");
    }
    // Translate lethal into boolean
    int temp;
    if (lethal == null) {
        throw new IllegalArgumentException("Parameter lethal can't be null");
    }
    temp = Integer.parseInt(lethal);
    boolean isLethal = (temp == 1);
    // Translate not into boolean
    if (not == null) {
        throw new IllegalArgumentException("Parameter not can't be null");
    }
    temp = Integer.parseInt(not);
    boolean notPolicy = (temp == 1);
    // If wildChar is defined then min, max and exact should not
    if (wildChar != null && (min != null || max != null || exact != null)) {
        throw new IllegalArgumentException("Ambiguous parameters: wildChar, min, max, exact");
    }
    // exat must be not null
    if (wildChar == null && min == null && max == null && exact == null) {
        throw new IllegalArgumentException("Ambiguous null params: wildChar, min, max, exact");
    }
    // If exact is defined then min and max should not
    if (exact != null && (min != null || max != null)) {
        throw new IllegalArgumentException("Ambiguous parameters: exact, min, max");
    }
    // For min, max and exact the type must be specified
    if (exact != null && exactType == null) {
        throw new IllegalArgumentException("Exact parameter can't be null");
    }
    if (min != null && minType == null) {
        throw new IllegalArgumentException("Min - minType parameters wrong");
    }
    if (max != null && maxType == null) {
        throw new IllegalArgumentException("Max - maxType parameters wrong");
    }
    // If both min and max are specified they must have the same type
    if (minType != null && maxType != null) {
        if (minType.compareTo(maxType) != 0) {
            throw new IllegalArgumentException("minType- maxType mismatch");
        }
    }
    //
    if (type == Constraint.STRING_WILDCHAR) {
        return new RegExpFilter(field, isLethal, wildChar, notPolicy);
    } else if (type == Constraint.EXACT) {
        if (exact != null && !exact.isEmpty() && exactType != null && !exactType.isEmpty()) {
            if (exactType.equals(Integer.class.getName())) {
                Integer integer;
                try {
                    integer = new Integer(exact);
                } catch (NumberFormatException e) {
                    throw new IllegalArgumentException("Wrong int parameter " + exact);
                }
                return new ExactFilter(field, isLethal, integer, notPolicy);
            } else if (exactType.equals(Long.class.getName())) {
                Long date = null;
                try {
                    date = Long.decode(exact);
                } catch (NumberFormatException e) {
                    throw new IllegalArgumentException("Wrong date parameter " + exact);
                }
                return new ExactFilter(field, isLethal, date, notPolicy);
            } else if (exactType.equals(String.class.getName())) {
                return new ExactFilter(field, isLethal, exact, notPolicy);
            } else if (exactType.equals(LogTypeHelper.class.getName())) {
                LogTypeHelper logType = LogTypeHelper.fromLogTypeDescription(exact);
                return new ExactFilter(field, isLethal, logType, notPolicy);
            } else {
                // Unrecognized type
                throw new IllegalArgumentException("Unrecognized type " + exactType);
            }
        } else {
            throw new IllegalArgumentException("Value and type can't be null/empty to build a ExactFilter");
        }
    } else if (type == Constraint.MINMAX || type == Constraint.MINIMUM || type == Constraint.MAXIMUM) {
        if (minType == null) {
            minType = maxType;
        } else {
            maxType = minType;
        }
        if (minType.equals(String.class.getName())) {
            return new MinMaxFilter(field, isLethal, min, max, notPolicy);
        } else if (minType.equals(Long.class.getName())) {
            Long minDate = null;
            Long maxDate = null;
            try {
                if (min != null) {
                    minDate = Long.decode(min);
                }
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException("Wrong min date parameter " + min);
            }
            try {
                if (max != null) {
                    maxDate = Long.decode(max);
                }
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException("Wrong max date parameter " + max);
            }
            return new MinMaxFilter(field, isLethal, minDate, maxDate, notPolicy);
        } else if (minType.equals(Integer.class.getName())) {
            Integer minInt = null;
            Integer maxInt = null;
            try {
                if (min != null) {
                    minInt = new Integer(min);
                }
                if (max != null) {
                    maxInt = new Integer(max);
                }
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException("Invalid min/max " + min + "/" + max);
            }
            return new MinMaxFilter(field, isLethal, minInt, maxInt, notPolicy);
        } else if (minType.equals(LogTypeHelper.class.getName())) {
            LogTypeHelper minLogType = null;
            LogTypeHelper maxLogType = null;
            try {
                if (min != null) {
                    minLogType = LogTypeHelper.fromLogTypeDescription(min);
                }
                if (max != null) {
                    maxLogType = LogTypeHelper.fromLogTypeDescription(max);
                }
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException("Invalid min/max " + min + "/" + max);
            }
            return new MinMaxFilter(field, isLethal, minLogType, maxLogType, notPolicy);
        } else {
            throw new IllegalArgumentException("Min/Max values/type can't be null/empty to build a MinMaxFilter");
        }
    } else {
        throw new Exception("Error building a filter");
    }
}
Also used : LogTypeHelper(com.cosylab.logging.engine.log.LogTypeHelper)

Example 4 with LogTypeHelper

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

the class FilterTypePanel method getFilter.

/* (non-Javadoc)
	 * @see com.cosylab.logging.settings.FilterParameterPanel#getFilter()
	 */
public Filter getFilter() throws FilterParameterException {
    boolean bmin = minimumCheck.isSelected();
    boolean bmax = maximumCheck.isSelected();
    boolean bexact = exactCheck.isSelected();
    LogTypeHelper min = null;
    LogTypeHelper max = null;
    if (bexact) {
        try {
            return new ExactFilter(getFieldIndex(), isLethal(), (LogTypeHelper) exact.getSelectedItem(), notCheck.isSelected());
        } catch (InvalidFilterConstraintException e) {
            e.printStackTrace();
            throw new FilterParameterException(e.getMessage());
        }
    }
    if (bmin) {
        min = (LogTypeHelper) minimum.getSelectedItem();
    }
    if (bmax) {
        max = (LogTypeHelper) maximum.getSelectedItem();
    }
    if ((min != null) && (max != null)) {
        if (min.compareTo(max) > -1) {
            throw new FilterParameterException("Minimum must be less than maximum");
        }
    }
    try {
        return new MinMaxFilter(getFieldIndex(), isLethal(), min, max, notCheck.isSelected());
    } catch (InvalidFilterConstraintException e) {
        throw new FilterParameterException(e.getMessage());
    }
}
Also used : MinMaxFilter(com.cosylab.logging.engine.MinMaxFilter) ExactFilter(com.cosylab.logging.engine.ExactFilter) LogTypeHelper(com.cosylab.logging.engine.log.LogTypeHelper) InvalidFilterConstraintException(com.cosylab.logging.engine.InvalidFilterConstraintException)

Example 5 with LogTypeHelper

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

the class FilterTypePanel method createComponents.

/* (non-Javadoc)
	 * @see com.cosylab.logging.settings.FilterParameterPanel#createComponents()
	 */
public void createComponents() {
    // Build the renderer for the combo boxes
    rendererMin = new LogTypeRenderer();
    rendererMax = new LogTypeRenderer();
    rendererExact = new LogTypeRenderer();
    JPanel panelTop = new JPanel(new GridBagLayout());
    add(panelTop, newConstraints(0, 4, 4, 4, 4));
    notCheck = new JCheckBox("Discard entries matching this filter");
    notCheck.setToolTipText("Keep/discard entries matching this filter");
    panelTop.add(notCheck, newConstraints(0, 4, 4, 4, 4));
    minimumCheck = new JCheckBox("Minimum value");
    minimumCheck.addItemListener(this);
    panelTop.add(minimumCheck, newConstraints(1, 4, 0, 0, 0));
    LogTypeHelper[] logTypes = LogTypeHelper.values();
    minimum = new JComboBox(logTypes);
    minimum.setSelectedIndex(0);
    minimum.setEditable(false);
    minimum.setMaximumRowCount(logTypes.length);
    minimum.setRenderer(rendererMin);
    panelTop.add(minimum, newConstraints(2, 0, 0, 4, 0));
    maximumCheck = new JCheckBox("Maximum value");
    maximumCheck.addItemListener(this);
    panelTop.add(maximumCheck, newConstraints(3, 4, 0, 0, 0));
    maximum = new JComboBox(logTypes);
    maximum.setSelectedIndex(0);
    maximum.setEditable(false);
    maximum.setMaximumRowCount(logTypes.length);
    maximum.setRenderer(rendererMax);
    panelTop.add(maximum, newConstraints(4, 0, 0, 4, 0));
    JPanel panelBottom = new JPanel(new GridBagLayout());
    add(panelBottom, newConstraints(1, 4, 4, 4, 4));
    exactCheck = new JCheckBox("Exact value");
    exactCheck.addItemListener(this);
    panelBottom.add(exactCheck, newConstraints(0, 4, 0, 0, 0));
    exact = new JComboBox(logTypes);
    exact.setSelectedIndex(0);
    exact.setEditable(false);
    exact.setMaximumRowCount(logTypes.length);
    exact.setRenderer(rendererExact);
    panelBottom.add(exact, newConstraints(1, 0, 0, 4, 0));
}
Also used : JCheckBox(javax.swing.JCheckBox) JPanel(javax.swing.JPanel) GridBagLayout(java.awt.GridBagLayout) JComboBox(javax.swing.JComboBox) LogTypeHelper(com.cosylab.logging.engine.log.LogTypeHelper)

Aggregations

LogTypeHelper (com.cosylab.logging.engine.log.LogTypeHelper)30 ILogEntry (com.cosylab.logging.engine.log.ILogEntry)8 Date (java.util.Date)6 AdditionalData (com.cosylab.logging.engine.log.ILogEntry.AdditionalData)5 JComboBox (javax.swing.JComboBox)5 ExactFilter (com.cosylab.logging.engine.ExactFilter)4 MinMaxFilter (com.cosylab.logging.engine.MinMaxFilter)4 LogTypeRenderer (com.cosylab.logging.settings.LogTypeRenderer)4 Filter (com.cosylab.logging.engine.Filter)3 RegExpFilter (com.cosylab.logging.engine.RegExpFilter)3 LogEntry (com.cosylab.logging.engine.log.LogEntry)3 SystemException (org.omg.CORBA.SystemException)3 LogLevels (alma.Logging.LoggingConfigurablePackage.LogLevels)2 LogLvlSelNotSupportedException (alma.acs.gui.loglevel.LogLvlSelNotSupportedException)2 AcsLogLevelDefinition (alma.acs.logging.level.AcsLogLevelDefinition)2 IsoDateFormat (alma.acs.util.IsoDateFormat)2 GridBagLayout (java.awt.GridBagLayout)2 Point (java.awt.Point)2 FieldPosition (java.text.FieldPosition)2 SimpleDateFormat (java.text.SimpleDateFormat)2