Example usage for java.util.logging Level parse

List of usage examples for java.util.logging Level parse

Introduction

In this page you can find the example usage for java.util.logging Level parse.

Prototype

public static synchronized Level parse(String name) throws IllegalArgumentException 

Source Link

Document

Parse a level name string into a Level.

Usage

From source file:MyLevel.java

public static void main(String[] argv) throws Exception {
    Logger logger = Logger.getLogger("com.mycompany");
    logger.log(MyLevel.DISASTER, "my disaster message");

    Level disaster = Level.parse("DISASTER");
    logger.log(disaster, "my disaster message");
}

From source file:net.ovres.tuxcourser.TuxCourser.java

public static void main(String[] argss) throws Exception {
    Options options = new Options();
    options.addOption(OptionBuilder.withArgName("WARN|INFO|FINE").hasArg()
            .withDescription("Set the log level. Valid values include WARN, INFO, and FINE.")
            .withLongOpt("loglevel").create("l"));
    options.addOption("h", "help", false, "Displays this help and exits");
    options.addOption("v", "version", false, "Displays version information and exits");

    options.addOption(OptionBuilder.withArgName("TYPE").hasArg()
            .withDescription("Sets the output type. Valid values are tux11 and ppracer05").withLongOpt("output")
            .create());//from ww  w. j a va 2  s . c o  m

    CommandLineParser parser = new GnuParser();
    CommandLine line = null;
    try {
        line = parser.parse(options, argss);
    } catch (ParseException exp) {
        System.err.println(exp.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java -jar TuxCourser.jar [Options]", "Options", options, "");
        System.exit(-1);
    }

    if (line.hasOption("loglevel")) {
        String lvl = line.getOptionValue("loglevel");
        Level logLevel = Level.parse(lvl);
        Logger.getLogger("net.ovres.tuxcourser").setLevel(logLevel);
    }

    if (line.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java -jar TuxCourser.jar [Options]", "Options", options, "");
        return;
    }
    if (line.hasOption("version")) {
        System.out.println("TuxCourser Version " + Settings.getVersion());
        return;
    }

    String[] remaining = line.getArgs();

    // Initialize all the different item and terrain types
    ModuleClassLoader.load();

    if (remaining.length == 0) { // Just show the gui.
        //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
        new net.ovres.tuxcourser.gui.TuxCourserGui().setVisible(true);
    } else if (remaining.length == 3) {
        new TuxCourser().convertCourse(new File(remaining[0]), new File(remaining[1]), remaining[2],
                TYPE_TUXRACER11);
    } else {
        usage();
        System.exit(-1);
    }
}

From source file:org.azrul.langmera.DecisionService.java

public static void main(String[] args) throws IOException {
    ConfigurationProvider config = null;
    ConfigFilesProvider configFilesProvider = () -> Arrays.asList(Paths.get("config.properties"));
    if (args.length <= 0) {
        ConfigurationSource source = new ClasspathConfigurationSource(configFilesProvider);
        config = new ConfigurationProviderBuilder().withConfigurationSource(source).build();
    } else {//w w w  .  j a  va  2 s . c  o  m
        ConfigurationSource source = new FilesConfigurationSource(configFilesProvider);
        Environment environment = new ImmutableEnvironment(args[0]);
        config = new ConfigurationProviderBuilder().withConfigurationSource(source).withEnvironment(environment)
                .build();

    }
    Logger logger = null;
    if (config.getProperty("log.file", String.class).isEmpty() == false) {
        FileHandler logHandler = new FileHandler(config.getProperty("log.file", String.class),
                config.getProperty("log.sizePerFile", Integer.class) * 1024 * 1024,
                config.getProperty("log.maxFileCount", Integer.class), true);
        logHandler.setFormatter(new SimpleFormatter());
        logHandler.setLevel(Level.INFO);

        Logger rootLogger = Logger.getLogger("");
        rootLogger.removeHandler(rootLogger.getHandlers()[0]);
        logHandler.setLevel(Level.parse(config.getProperty("log.level", String.class)));
        rootLogger.setLevel(Level.parse(config.getProperty("log.level", String.class)));
        rootLogger.addHandler(logHandler);

        logger = rootLogger;
    } else {
        logger = Logger.getGlobal();
    }

    VertxOptions options = new VertxOptions();
    options.setMaxEventLoopExecuteTime(Long.MAX_VALUE);
    options.setWorkerPoolSize(config.getProperty("workerPoolSize", Integer.class));
    options.setEventLoopPoolSize(40);

    Vertx vertx = Vertx.vertx(options);
    vertx.deployVerticle(new DecisionService(logger, config));
    vertx.deployVerticle(new SaveToDB(logger, config));

}

From source file:GIST.IzbirkomExtractor.IzbirkomExtractor.java

/**
 * @param args//from   w ww .ja  v a 2s  . co m
 */
public static void main(String[] args) {

    // process command-line options
    Options options = new Options();
    options.addOption("n", "noaddr", false, "do not do any address matching (for testing)");
    options.addOption("i", "info", false, "create and populate address information table");
    options.addOption("h", "help", false, "this message");

    // database connection
    options.addOption("s", "server", true, "database server to connect to");
    options.addOption("d", "database", true, "OSM database name");
    options.addOption("u", "user", true, "OSM database user name");
    options.addOption("p", "pass", true, "OSM database password");

    // logging options
    options.addOption("l", "logdir", true, "log file directory (default './logs')");
    options.addOption("e", "loglevel", true, "log level (default 'FINEST')");

    // automatically generate the help statement
    HelpFormatter help_formatter = new HelpFormatter();

    // database URI for connection
    String dburi = null;

    // Information message for help screen
    String info_msg = "IzbirkomExtractor [options] <html_directory>";

    try {
        CommandLineParser parser = new GnuParser();
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption('h') || cmd.getArgs().length != 1) {
            help_formatter.printHelp(info_msg, options);
            System.exit(1);
        }

        /* prohibit n and i together */
        if (cmd.hasOption('n') && cmd.hasOption('i')) {
            System.err.println("Options 'n' and 'i' cannot be used together.");
            System.exit(1);
        }

        /* require database arguments without -n */
        if (cmd.hasOption('n')
                && (cmd.hasOption('s') || cmd.hasOption('d') || cmd.hasOption('u') || cmd.hasOption('p'))) {
            System.err.println("Options 'n' and does not need any databse parameters.");
            System.exit(1);
        }

        /* require all 4 database options to be used together */
        if (!cmd.hasOption('n')
                && !(cmd.hasOption('s') && cmd.hasOption('d') && cmd.hasOption('u') && cmd.hasOption('p'))) {
            System.err.println(
                    "For database access all of the following arguments have to be specified: server, database, user, pass");
            System.exit(1);
        }

        /* useful variables */
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'kk:mm");
        String dateString = formatter.format(new Date());

        /* setup logging */
        File logdir = new File(cmd.hasOption('l') ? cmd.getOptionValue('l') : "logs");
        FileUtils.forceMkdir(logdir);
        File log_file_name = new File(
                logdir + "/" + IzbirkomExtractor.class.getName() + "-" + formatter.format(new Date()) + ".log");
        FileHandler log_file = new FileHandler(log_file_name.getPath());

        /* create "latest" link to currently created log file */
        Path latest_log_link = Paths.get(logdir + "/latest");
        Files.deleteIfExists(latest_log_link);
        Files.createSymbolicLink(latest_log_link, Paths.get(log_file_name.getName()));

        log_file.setFormatter(new SimpleFormatter());
        LogManager.getLogManager().reset(); // prevents logging to console
        logger.addHandler(log_file);
        logger.setLevel(cmd.hasOption('e') ? Level.parse(cmd.getOptionValue('e')) : Level.FINEST);

        // open directory with HTML files and create file list
        File dir = new File(cmd.getArgs()[0]);
        if (!dir.isDirectory()) {
            System.err.println("Unable to find directory '" + cmd.getArgs()[0] + "', exiting");
            System.exit(1);
        }
        PathMatcher pmatcher = FileSystems.getDefault()
                .getPathMatcher("glob:?  * ?*.html");
        ArrayList<File> html_files = new ArrayList<>();
        for (Path file : Files.newDirectoryStream(dir.toPath()))
            if (pmatcher.matches(file.getFileName()))
                html_files.add(file.toFile());
        if (html_files.size() == 0) {
            System.err.println("No matching HTML files found in '" + dir.getAbsolutePath() + "', exiting");
            System.exit(1);
        }

        // create csvResultSink
        FileOutputStream csvout_file = new FileOutputStream("parsed_addresses-" + dateString + ".csv");
        OutputStreamWriter csvout = new OutputStreamWriter(csvout_file, "UTF-8");
        ResultSink csvResultSink = new CSVResultSink(csvout, new CSVStrategy('|', '"', '#'));

        // Connect to DB and osmAddressMatcher
        AddressMatcher osmAddressMatcher;
        DBSink dbSink = null;
        DBInfoSink dbInfoSink = null;
        if (cmd.hasOption('n')) {
            osmAddressMatcher = new DummyAddressMatcher();
        } else {
            dburi = "jdbc:postgresql://" + cmd.getOptionValue('s') + "/" + cmd.getOptionValue('d');
            Connection con = DriverManager.getConnection(dburi, cmd.getOptionValue('u'),
                    cmd.getOptionValue('p'));
            osmAddressMatcher = new OsmAddressMatcher(con);
            dbSink = new DBSink(con);
            if (cmd.hasOption('i'))
                dbInfoSink = new DBInfoSink(con);
        }

        /* create resultsinks */
        SinkMultiplexor sm = SinkMultiplexor.newSinkMultiplexor();
        sm.addResultSink(csvResultSink);
        if (dbSink != null) {
            sm.addResultSink(dbSink);
            if (dbInfoSink != null)
                sm.addResultSink(dbInfoSink);
        }

        // create tableExtractor
        TableExtractor te = new TableExtractor(osmAddressMatcher, sm);

        // TODO: printout summary of options: processing date/time, host, directory of HTML files, jdbc uri, command line with parameters

        // iterate through files
        logger.info("Start processing " + html_files.size() + " files in " + dir);
        for (int i = 0; i < html_files.size(); i++) {
            System.err.println("Parsing #" + i + ": " + html_files.get(i));
            te.processHTMLfile(html_files.get(i));
        }

        System.err.println("Processed " + html_files.size() + " HTML files");
        logger.info("Finished processing " + html_files.size() + " files in " + dir);

    } catch (ParseException e1) {
        System.err.println("Failed to parse CLI: " + e1.getMessage());
        help_formatter.printHelp(info_msg, options);
        System.exit(1);
    } catch (IOException e) {
        System.err.println("I/O Exception: " + e.getMessage());
        e.printStackTrace();
        System.exit(1);
    } catch (SQLException e) {
        System.err.println("Database '" + dburi + "': " + e.getMessage());
        System.exit(1);
    } catch (ResultSinkException e) {
        System.err.println("Failed to initialize ResultSink: " + e.getMessage());
        System.exit(1);
    } catch (TableExtractorException e) {
        System.err.println("Failed to initialize Table Extractor: " + e.getMessage());
        System.exit(1);
    } catch (CloneNotSupportedException | IllegalAccessException | InstantiationException e) {
        System.err.println("Something really odd happened: " + e.getMessage());
        e.printStackTrace();
        System.exit(1);
    }
}

From source file:shuffle.fwk.ShuffleController.java

/**
 * The main which starts the program./*from www  . j  a v a 2 s. co m*/
 * 
 * @param args
 *           unused.
 */
public static void main(String... args) {
    String userHomeArg = null;
    String levelToSetArg = null;

    if (args != null && args.length > 0) {
        userHomeArg = args[0];
        if (args.length > 1) {
            levelToSetArg = args[1];
        }
    }

    if (userHomeArg == null) {
        userHomeArg = System.getProperty("user.home") + File.separator + "Shuffle-Move";
    }
    setUserHome(userHomeArg);
    try {
        FileHandler handler = new FileHandler();
        Logger toRoot = LOG;
        while (toRoot.getParent() != null) {
            toRoot = toRoot.getParent();
        }
        toRoot.addHandler(handler);
    } catch (SecurityException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    if (levelToSetArg != null) {
        try {
            Level levelToSet = Level.parse(args[1]);
            Logger.getLogger(SimulationTask.class.getName()).setLevel(levelToSet);
            SimulationTask.setLogFiner(levelToSet.intValue() <= Level.FINER.intValue());
            Logger.getLogger(ShuffleModel.class.getName()).setLevel(levelToSet);
        } catch (Exception e) {
            LOG.fine("Cannot set simulation logging to that level: " + StringUtils.join(args));
        }
    }

    ShuffleController ctrl = new ShuffleController();
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            ctrl.getFrame().launch();
        }
    });
}

From source file:org.icesquirrel.Squirrel.java

public static void main(String[] args) throws Exception {
    Options o = new Options();
    o.addOption("?", "help", true, "Display help and exit.");
    o.addOption("n", "namespace", true, "Namespace of generated classes.");
    o.addOption("m", "mode", true, "Mode. One of " + Arrays.asList(Mode.values()));
    o.addOption("o", "output", true,
            "Output directory for compiled classes. Default is current working directory.");
    o.addOption("l", "level", true,
            "Log level. One of ALL, CONFIG, FINE, FINER, FINEST, WARN, INFO, SEVERE, OFF");
    CommandLine cli = new GnuParser().parse(o, args);

    Squirrel sq = new Squirrel();

    if (cli.hasOption('?') || cli.getArgList().size() == 0) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(Squirrel.class.getName()
                + " [-?|--help] [-m <mode>|--mode <mode>] [-o <output directory>|--output <output directory>] [-l <log level>|--log <log level>] <script1.nut> [<script2.nut> ..] [-- <scriptArg1> <scriptArg2> ..]",
                o);// w w w. j a  va2 s .c  o m
        System.exit(1);
    }

    // Namespace
    if (cli.hasOption('n')) {
        sq.setNamespace(cli.getOptionValue('n'));
    }

    // Mode
    if (cli.hasOption('m')) {
        sq.setMode(Mode.valueOf(cli.getOptionValue('m')));
    }

    // Log level
    if (cli.hasOption('l')) {
        Squirrel.setLogLevel(Level.parse(cli.getOptionValue('l')));
    }

    // Output
    if (cli.hasOption('o')) {
        File dir = new File(cli.getOptionValue('o'));
        sq.setOutput(dir);
    }

    // Process
    List<String> scriptArgList = new ArrayList<>();
    List<String> files = new ArrayList<>();
    boolean scriptArgs = false;
    for (String a : cli.getArgs()) {
        if (a.equals("--") && !scriptArgs) {
            scriptArgs = true;
        } else {
            if (scriptArgs) {
                scriptArgList.add(a);
            } else {
                files.add(a);
            }
        }
    }

    for (String f : files) {
        sq.process(new File(f), scriptArgList.toArray(new String[0]));
    }
}

From source file:LogWindow.java

private WindowHandler() {
    LogManager manager = LogManager.getLogManager();
    String className = this.getClass().getName();
    String level = manager.getProperty(className + ".level");
    setLevel(level != null ? Level.parse(level) : Level.INFO);
    if (window == null)
        window = new LogWindow();
}

From source file:io.stallion.services.LogFilter.java

public LogFilter(Level defaultLevel, Map<String, String> packageLogLevelMap) {
    for (Map.Entry<String, String> entry : packageLogLevelMap.entrySet()) {
        String packageName = entry.getKey().replace("io.stallion", ".");
        this.packageLogLevelMap.put(packageName, Level.parse(entry.getValue().toUpperCase()));
    }/*from   w w  w . ja  va2 s. c  o  m*/
    this.defaultLevel = defaultLevel;
}

From source file:io.trivium.Central.java

public static void setLogLevel(String level) {
    Logger logger = Logger.getLogger("");
    logger.setLevel(Level.parse(level.toUpperCase()));
}

From source file:eu.edisonproject.training.wsd.WikipediaOnline.java

@Override
public void configure(Properties properties) {
    super.configure(properties);

    Level level = Level.parse(properties.getProperty("log.level", "INFO"));
    Handler[] handlers = Logger.getLogger("").getHandlers();
    for (int index = 0; index < handlers.length; index++) {
        handlers[index].setLevel(level);
    }/*from ww w.  j a  va2s .  com*/
    LOGGER.setLevel(level);
}