Example usage for java.util.logging LogManager getLogManager

List of usage examples for java.util.logging LogManager getLogManager

Introduction

In this page you can find the example usage for java.util.logging LogManager getLogManager.

Prototype

public static LogManager getLogManager() 

Source Link

Document

Returns the global LogManager object.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    // Register for the event
    LogManager.getLogManager().addPropertyChangeListener(new PropertyChangeListener() {
        // This method is called when configuration file is reread
        public void propertyChange(PropertyChangeEvent evt) {
            String propName = evt.getPropertyName();
            Object oldValue = evt.getOldValue();
            Object newValue = evt.getOldValue();
            // All values are null
        }//from ww  w  .j  ava  2 s.  c om
    });
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    LogManager lm = LogManager.getLogManager();
    Logger logger;/*  w  w w  . ja  v  a  2s  . com*/
    FileHandler fh = new FileHandler("log_test.txt");

    logger = Logger.getLogger("LoggingExample1");

    lm.addLogger(logger);
    logger.setLevel(Level.INFO);
    fh.setFormatter(new XMLFormatter());

    logger.addHandler(fh);
    //logger.setUseParentHandlers(false);
    logger.log(Level.INFO, "test 1");
    logger.log(Level.INFO, "test 2");
    logger.log(Level.INFO, "test 3");
    fh.close();
}

From source file:LoggingExample1.java

public static void main(String args[]) {
    try {//  w ww. j  a  v  a  2  s  .c o  m
        LogManager lm = LogManager.getLogManager();
        Logger logger;
        FileHandler fh = new FileHandler("log_test.txt");

        logger = Logger.getLogger("LoggingExample1");

        lm.addLogger(logger);
        logger.setLevel(Level.INFO);
        fh.setFormatter(new XMLFormatter());

        logger.addHandler(fh);
        //logger.setUseParentHandlers(false);
        logger.log(Level.INFO, "test 1");
        logger.log(Level.INFO, "test 2");
        logger.log(Level.INFO, "test 3");
        fh.close();
    } catch (Exception e) {
        System.out.println("Exception thrown: " + e);
        e.printStackTrace();
    }
}

From source file:HTMLFormatter.java

public static void main(String args[]) throws Exception {
    LogManager lm = LogManager.getLogManager();
    Logger parentLogger, childLogger;
    FileHandler xml_handler = new FileHandler("log_output.xml");
    FileHandler html_handler = new FileHandler("log_output.html");
    parentLogger = Logger.getLogger("ParentLogger");
    childLogger = Logger.getLogger("ParentLogger.ChildLogger");

    lm.addLogger(parentLogger);/* w  w w .  ja  v a2s . com*/

    lm.addLogger(childLogger);

    parentLogger.setLevel(Level.WARNING);
    childLogger.setLevel(Level.ALL);
    xml_handler.setFormatter(new XMLFormatter());
    html_handler.setFormatter(new HTMLFormatter());

    parentLogger.addHandler(xml_handler);
    childLogger.addHandler(html_handler);

    childLogger.log(Level.FINE, "This is a fine log message");
    childLogger.log(Level.SEVERE, "This is a severe log message");
    xml_handler.close();
    html_handler.close();
}

From source file:com.hazelcast.hibernate.app.Main.java

public static void main(String[] args) throws Exception {
    LogManager.getLogManager().reset();
    SLF4JBridgeHandler.install();//  w w w.  j  a v  a2  s  .c o m

    ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("/app-context.xml");
    Executor executor = applicationContext.getBean(Executor.class);

    // Start and wait for finishing work
    executor.execute();

    applicationContext.close();
}

From source file:pav.player.Main.java

/**
 * Entry point of the program.//from  w  w w .j a  v a2s.c  om
 * 
 * @param args Startup arguments
 */
public static void main(String[] args) {
    System.out.println("----------");
    System.out.println("PAV Player");
    System.out.println("----------\n");

    _initConfig(args);

    try {
        LogManager.getLogManager()
                .readConfiguration(new ByteArrayInputStream("org.jaudiotagger.level = OFF".getBytes()));
    } catch (Exception e) {
        Console.error("Error while disabling jAudioTagger logging: " + e.getMessage());
    }

    PApplet.main(new String[] { "pav.player.Player" });
}

From source file:script.manager.App.java

public static void main(String[] args) throws IOException {
    try (final InputStream in = new FileInputStream(LOGGER_PROPERTY_FILE);) {
        LogManager.getLogManager().readConfiguration(in);
    }//from  www  . ja v a  2  s . c o m
    final App app = new App();
    if (ArrayUtils.isEmpty(args)) {
        app.printUsage();
        return;
    }
    String internalJsonQuery;
    try {
        internalJsonQuery = QueryUtils.buildInternalQuery(args);
    } catch (Exception ex) {
        LOG.log(Level.SEVERE, null, ex);
        app.printUsage();
        return;
    }
    app.parse(internalJsonQuery);
}

From source file:com.github.thesmartenergy.sparql.generate.generator.CMDGenerator.java

public static void main(String[] args) {

    List<String> formats = Arrays.asList("TTL", "TURTLE", "NTRIPLES", "TRIG", "RDFXML", "JSONLD");

    try {/*from   w ww . ja  v  a 2s. c om*/
        CommandLine cl = CMDConfigurations.parseArguments(args);

        String query = "";
        String outputFormat = "TTL";

        if (cl.getArgList().size() == 0) {
            CMDConfigurations.displayHelp();
            return;
        }

        fileManager = FileManager.makeGlobal();
        if (cl.hasOption('l')) {
            Enumeration<String> loggers = LogManager.getLogManager().getLoggerNames();
            while (loggers.hasMoreElements()) {
                java.util.logging.Logger element = LogManager.getLogManager().getLogger(loggers.nextElement());
                element.setLevel(Level.OFF);
            }
            Logger.getRootLogger().setLevel(org.apache.log4j.Level.OFF);

        }
        LOG = Logger.getLogger(CMDGenerator.class);

        //get query file path
        //check if the file exists
        if (cl.hasOption("qf")) {
            String file_path = cl.getOptionValue("qf");
            File f = new File(file_path);
            if (f.exists() && !f.isDirectory()) {
                FileInputStream fisTargetFile = new FileInputStream(f);
                query = IOUtils.toString(fisTargetFile, "UTF-8");
                LOG.debug("\n\nRead SPARQL-Generate Query ..\n" + query + "\n\n");
            } else {
                LOG.error("File " + file_path + " not found.");
            }
        }

        //get query string
        if (cl.hasOption("qs")) {
            query = cl.getOptionValue("qs");
        }
        System.out.println("Query:" + query);

        //get and validate the output format
        if (cl.hasOption("f")) {
            String format = cl.getOptionValue("f");
            if (formats.contains(format)) {
                outputFormat = format;
            } else {
                LOG.error("Invalid output format," + cl.getOptionProperties("f").getProperty("description"));
                return;
            }
        }

        Model configurationModel = null;
        String conf = "";
        if (cl.hasOption("c")) {
            conf = cl.getOptionValue("c");
            configurationModel = ProcessQuery.generateConfiguration(conf);
        }

        String output = ProcessQuery.process(query, conf, outputFormat);
        System.out.println(output);

    } catch (org.apache.commons.cli.ParseException ex) {
        LOG.error(ex);
    } catch (FileNotFoundException ex) {
        LOG.error(ex);
    } catch (IOException ex) {
        LOG.error(ex);
    }

}

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

/**
 * Main function which start drawing the cellular automata.
 *
 * @param args Command line arguments./* ww  w . j  a  v  a  2  s.com*/
 */
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:mx.unam.fesa.mss.MSSMain.java

/**
 * @param args//from  w  w  w.  java  2  s .c  o m
 */
@SuppressWarnings("static-access")
public static void main(String[] args) {

    //
    // managing command line options using commons-cli
    //

    Options options = new Options();

    // help option
    //
    options.addOption(
            OptionBuilder.withDescription("Prints this message.").withLongOpt("help").create(OPT_HELP));

    // port option
    //
    options.addOption(OptionBuilder.withDescription("The port in which the MineSweeperServer will listen to.")
            .hasArg().withType(new Integer(0)).withArgName("PORT").withLongOpt("port").create(OPT_PORT));

    // parsing options
    //
    int port = DEFAULT_PORT;
    try {
        // using GNU standard
        //
        CommandLine line = new GnuParser().parse(options, args);

        if (line.hasOption(OPT_HELP)) {
            new HelpFormatter().printHelp("mss [options]", options);
            return;
        }

        if (line.hasOption(OPT_PORT)) {
            try {
                port = (Integer) line.getOptionObject(OPT_PORT);
            } catch (Exception e) {
            }
        }
    } catch (ParseException e) {
        System.err.println("Could not parse command line options correctly: " + e.getMessage());
        return;
    }

    //
    // configuring logging services
    //

    try {
        LogManager.getLogManager()
                .readConfiguration(ClassLoader.getSystemResourceAsStream(DEFAULT_LOGGING_CONFIG_FILE));
    } catch (Exception e) {
        throw new Error("Could not load logging properties file", e);
    }

    //
    // setting up UDP server
    //      

    try {
        new MSServer(port);
    } catch (Exception e) {
        LoggerFactory.getLogger(MSSMain.class).error("Could not execute MineSweeper server: ", e);
    }
}