Example usage for java.util.logging Handler setLevel

List of usage examples for java.util.logging Handler setLevel

Introduction

In this page you can find the example usage for java.util.logging Handler setLevel.

Prototype

public synchronized void setLevel(Level newLevel) throws SecurityException 

Source Link

Document

Set the log level specifying which message levels will be logged by this Handler .

Usage

From source file:de.fosd.jdime.JDimeWrapper.java

public static void main(String[] args) throws IOException, InterruptedException {
    // setup logging
    Logger root = Logger.getLogger(JDimeWrapper.class.getPackage().getName());
    root.setLevel(Level.WARNING);

    for (Handler handler : root.getHandlers()) {
        handler.setLevel(Level.WARNING);
    }//from w  ww.j av  a2  s  .  com

    // setup JDime using the MergeContext
    MergeContext context = new MergeContext();
    context.setPretend(true);
    context.setQuiet(false);

    // prepare the list of input files
    ArtifactList<FileArtifact> inputArtifacts = new ArtifactList<>();

    for (String filename : args) {
        try {
            File file = new File(filename);

            // the revision name, this will be used as condition for ifdefs
            // as an example, I'll just use the filenames
            Revision rev = new Revision(FilenameUtils.getBaseName(file.getPath()));
            FileArtifact newArtifact = new FileArtifact(rev, file);

            inputArtifacts.add(newArtifact);
        } catch (FileNotFoundException e) {
            System.err.println("Input file not found: " + filename);
        }
    }

    context.setInputFiles(inputArtifacts);

    // setup strategies
    MergeStrategy<FileArtifact> structured = new StructuredStrategy();
    MergeStrategy<FileArtifact> conditional = new NWayStrategy();

    // run the merge first with structured strategy to see whether there are conflicts
    context.setMergeStrategy(structured);
    context.collectStatistics(true);
    Operation<FileArtifact> merge = new MergeOperation<>(context.getInputFiles(), context.getOutputFile(), null,
            null, context.isConditionalMerge());
    merge.apply(context);

    // if there are no conflicts, run the conditional strategy
    if (context.getStatistics().hasConflicts()) {
        context = new MergeContext(context);
        context.collectStatistics(false);
        context.setMergeStrategy(conditional);
        // use regular merging outside of methods
        context.setConditionalOutsideMethods(false);
        // we have to recreate the operation because now we will do a conditional merge
        merge = new MergeOperation<>(context.getInputFiles(), context.getOutputFile(), null, null,
                context.isConditionalMerge());
        merge.apply(context);
    }
}

From source file:org.wor.drawca.DrawCAMain.java

/**
 * Main function which start drawing the cellular automata.
 *
 * @param args Command line arguments./*from   ww w  .  java2 s.  c om*/
 */
public static void main(final String[] args) {
    final Logger log = Logger.getGlobal();
    LogManager.getLogManager().reset();

    Options options = new Options();
    boolean hasArgs = true;

    // TODO: show defaults in option description
    options.addOption("h", "help", !hasArgs, "Show this help message");
    options.addOption("pci", "perclickiteration", !hasArgs, "Generate one line per mouse click");

    options.addOption("v", "verbose", hasArgs, "Verbosity level [-1,7]");
    options.addOption("r", "rule", hasArgs, "Rule number to use 0-255");
    options.addOption("wh", "windowheigth", hasArgs, "Draw window height");
    options.addOption("ww", "windowwidth", hasArgs, "Draw window width");
    options.addOption("x", "xscalefactor", hasArgs, "X Scale factor");
    options.addOption("y", "yscalefactor", hasArgs, "Y scale factor");
    options.addOption("f", "initline", hasArgs, "File name with Initial line.");

    CommandLineParser parser = new PosixParser();
    CommandLine cmd;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        e.printStackTrace();
        showHelp(options);
        return;
    }

    // Options without an argument
    if (cmd.hasOption("h")) {
        showHelp(options);
        return;
    }
    final boolean perClickIteration = cmd.hasOption("pci");

    // Options with an argument
    final int verbosityLevel = Integer.parseInt(cmd.getOptionValue('v', "0"));
    final int rule = Integer.parseInt(cmd.getOptionValue('r', "110"));
    final int windowHeigth = Integer.parseInt(cmd.getOptionValue("wh", "300"));
    final int windowWidth = Integer.parseInt(cmd.getOptionValue("ww", "400"));
    final float xScaleFactor = Float.parseFloat(cmd.getOptionValue('x', "2.0"));
    final float yScaleFactor = Float.parseFloat(cmd.getOptionValue('y', "2.0"));
    final String initLineFile = cmd.getOptionValue('f', "");

    final Level logLevel = VERBOSITY_MAP.get(verbosityLevel);
    log.setLevel(logLevel);

    // Set log handler
    Handler consoleHandler = new ConsoleHandler();
    consoleHandler.setLevel(logLevel);
    log.addHandler(consoleHandler);

    log.info("Log level set to: " + log.getLevel());

    // Read initial line from a file
    String initLine = "";
    if (initLineFile.length() > 0) {
        Path initLineFilePath = FileSystems.getDefault().getPath(initLineFile);
        try {
            // Should be string of ones and zeros only
            initLine = new String(Files.readAllBytes(initLineFilePath), "UTF-8");
        } catch (IOException e) {
            System.err.format("IOException: %s\n", e);
            return;
        }
    }

    SwingUtilities.invokeLater(new RunGUI(windowWidth, windowHeigth, xScaleFactor, yScaleFactor, rule, initLine,
            perClickIteration));
}

From source file:io.mesosphere.mesos.frameworks.cassandra.framework.Main.java

public static void main(final String[] args) {
    int status;//from   ww  w .  j a va 2 s  .  c  o  m
    try {
        final Handler[] handlers = LogManager.getLogManager().getLogger("").getHandlers();
        for (final Handler handler : handlers) {
            handler.setLevel(Level.OFF);
        }
        org.slf4j.LoggerFactory.getLogger("slf4j-logging").debug("Installing SLF4JLogging");
        SLF4JBridgeHandler.install();
        status = _main();
    } catch (final SystemExitException e) {
        LOGGER.error(e.getMessage());
        status = e.status;
    } catch (final UnknownHostException e) {
        LOGGER.error("Unable to resolve local interface for http server");
        status = 6;
    } catch (final Throwable e) {
        LOGGER.error("Unhandled fatal exception", e);
        status = 10;
    }

    System.exit(status);
}

From source file:org.archive.crawler.processor.recrawl.PersistProcessor.java

/**
 * Utility main for importing a log into a BDB-JE environment or moving a
 * database between environments (2 arguments), or simply dumping a log
 * to stderr in a more readable format (1 argument). 
 * // ww  w .  java2  s. c o m
 * @param args command-line arguments
 * @throws DatabaseException
 * @throws IOException
 */
public static void main(String[] args) throws DatabaseException, IOException {
    Handler handler = new ConsoleHandler();
    handler.setLevel(Level.ALL);
    handler.setFormatter(new OneLineSimpleLogger());
    logger.addHandler(handler);
    logger.setUseParentHandlers(false);

    if (args.length == 2) {
        logger.setLevel(Level.INFO);
        populatePersistEnv(args[0], new File(args[1]));
    } else if (args.length == 1) {
        logger.setLevel(Level.FINE);
        populatePersistEnv(args[0], null);
    } else {
        System.out.println("Arguments: ");
        System.out.println("    source [target]");
        System.out.println("...where source is either a txtser log file or BDB env dir");
        System.out.println("and target, if present, is a BDB env dir. ");
        return;
    }
}

From source file:primarydatamanager.PrimaryDataManager.java

public static void main(String[] args) {
    // setup logging
    try {/*from   w w  w . ja va2  s.  c o  m*/
        // Get the default Logger
        Logger mainLogger = Logger.getLogger("");
        mainLogger.setLevel(Level.FINEST);

        Handler consoleHandler = mainLogger.getHandlers()[0];
        consoleHandler.setLevel(Level.FINEST);
        consoleHandler.setFormatter(new VerySimpleFormatter());

        // Add a file handler
        new File("log").mkdir();
        Handler fileHandler = new FileHandler("log/datamanager.log", 50000, 2, true);
        fileHandler.setLevel(Level.INFO);
        mainLogger.addHandler(fileHandler);
    } catch (IOException exc) {
        System.out.println("Can't create log file");
        exc.printStackTrace();
    }

    // Start the update
    if (args.length == 0) {
        System.out.println("USAGE: PrimaryDataManager [-forceCompleteUpdate [channel{;channel}]] groups...");
        System.exit(1);
    } else {
        try {
            PrimaryDataManager manager = new PrimaryDataManager(new File("."));
            ArrayList<String> groupNames = new ArrayList<String>();
            for (int i = 0; i < args.length; i++) {
                if (args[i].equalsIgnoreCase("-forceCompleteUpdate")) {
                    if ((i + 1) >= args.length) {
                        System.out.println("You have to specify a colon separated "
                                + "list of channels after -forceCompleteUpdate");
                        System.exit(1);
                    } else {
                        i++;
                        StringTokenizer tokenizer = new StringTokenizer(args[i], ":");
                        while (tokenizer.hasMoreTokens()) {
                            manager.forceCompleteUpdateFor(tokenizer.nextToken());
                        }
                    }
                } else {
                    final String[] groups = args[i].split(",");
                    groupNames.addAll(Arrays.asList(groups));
                }
            }

            if (groupNames.size() == 0) {
                System.out.println("Please specify at least one channel group");
                System.exit(-1);
            }

            if (!manager.doesPreparedExist()) {
                System.out.println(
                        "The prepared directory is missing, this directory is very important and shouldn't "
                                + "be deleted, because this leeds to massiv problems.");
                System.exit(-1);
            }

            if (!manager.createLockFile()) {
                System.out.println("The PrimaryDataManager is already running.");
                System.exit(-1);
            }

            String[] groupNamesArr = new String[groupNames.size()];
            groupNames.toArray(groupNamesArr);
            manager.setGroupNames(groupNamesArr);

            manager.updateRawDataDir();

            manager.deleteLockFile();

            // Exit with error code 2 if some day programs were put into quarantine
            if (manager.mRawDataProcessor.getQuarantineCount() != 0) {
                System.exit(2);
            }
        } catch (PreparationException exc) {
            exc.printStackTrace();
            System.exit(1);
        }
    }
}

From source file:havocx42.Program.java

private static void initRootLogger() throws SecurityException, IOException {

    FileHandler fileHandler;//from   w w w  .  jav a 2 s .co m
    fileHandler = new FileHandler("PRWeaponStats.%u.%g.txt", 1024 * 1024 * 8, 3, false);
    fileHandler.setLevel(Level.FINEST);
    fileHandler.setFormatter(new SimpleFormatter());
    Logger rootLogger = Logger.getLogger("");
    Handler[] handlers = rootLogger.getHandlers();
    for (Handler handler : handlers) {
        handler.setLevel(Level.INFO);
    }
    rootLogger.setLevel(Level.FINEST);
    rootLogger.addHandler(fileHandler);
}

From source file:org.jumpmind.metl.StartWebServer.java

protected static void disableJettyLogging() {
    System.setProperty("org.eclipse.jetty.util.log.class", JavaUtilLog.class.getName());
    Logger.getLogger(JavaUtilLog.class.getName()).setLevel(Level.SEVERE);
    Logger rootLogger = Logger.getLogger("org.eclipse.jetty");
    for (Handler handler : rootLogger.getHandlers()) {
        handler.setLevel(Level.SEVERE);
    }//from   w w  w . j  a  v  a2s .  com
    rootLogger.setLevel(Level.SEVERE);
}

From source file:jshm.logging.Log.java

public static void configTestLogging() {
    Handler consoleHandler = new ConsoleHandler();
    consoleHandler.setLevel(Level.ALL);
    consoleHandler.setFormatter(new OneLineFormatter());

    Logger cur = Logger.getLogger("");
    removeHandlers(cur);//from w  w  w.  ja v a  2s. c  o  m
    //      cur.setLevel(Level.ALL);

    cur.addHandler(consoleHandler);

    cur = Logger.getLogger("jshm");
    cur.setLevel(Level.ALL);

    cur = Logger.getLogger("httpclient.wire.header");
    cur.setLevel(Level.ALL);

    //      cur = Logger.getLogger("org.hibernate");
    //      removeHandlers(cur);
    //      
    //      cur.setLevel(Level.INFO);
}

From source file:it.unibo.alchemist.utils.L.java

/**
 * @param h/*from   w  w w . j  ava 2 s .co  m*/
 *            the handler to attach
 */
@Deprecated
public static void addHandler(final Handler h) {
    h.setLevel(Level.ALL);
    LOGGER.addHandler(h);
}

From source file:org.ow2.mind.doc.Launcher.java

private static void initLogger() {
    final Handler consoleHandler = new ConsoleHandler();
    consoleHandler.setLevel(Level.ALL);
    logger.setLevel(Level.INFO);/* ww  w . ja v a 2 s  . c  o  m*/
    logger.setUseParentHandlers(false);
    logger.addHandler(consoleHandler);
}