Example usage for java.util.logging Logger config

List of usage examples for java.util.logging Logger config

Introduction

In this page you can find the example usage for java.util.logging Logger config.

Prototype

ConfigurationData config

To view the source code for java.util.logging Logger config.

Click Source Link

Usage

From source file:Logging.java

public static void main(String[] args) {
    Logger log = Logger.getLogger("global");

    log.finest("A");
    log.finer("B");
    log.fine("C");
    log.config("D");
    log.info("E");
    log.warning("O");
    log.severe("A");
}

From source file:MainClass.java

public static void main(String[] args) {
    Logger logger = Logger.getLogger("com.java2s.log");

    logger.severe("severe");
    logger.warning("warning");
    logger.info("info");
    logger.config("config");
    logger.fine("fine");
    logger.finer("finer");
    logger.finest("value =" + 42);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Logger logger = Logger.getLogger("com.mycompany");
    FileHandler fh = new FileHandler("mylog.txt");
    fh.setFormatter(new SimpleFormatter());
    logger.addHandler(fh);/*from ww  w . ja v  a2 s  .c  o m*/

    // fh = new FileHandler("mylog.xml");
    // fh.setFormatter(new XMLFormatter());
    // logger.addHandler(fh);

    // Log a few messages
    logger.severe("my severe message");
    logger.warning("my warning message");
    logger.info("my info message");
    logger.config("my config message");
    logger.fine("my fine message");
    logger.finer("my finer message");
    logger.finest("my finest message");
}

From source file:org.jamwiki.utils.WikiLogger.java

/**
 *
 *///from ww w. j a v  a2  s .  co  m
private static void initializeLogParams() {
    FileInputStream stream = null;
    try {
        File propertyFile = WikiLogger.loadProperties();
        stream = new FileInputStream(propertyFile);
        Properties properties = new Properties();
        properties.load(stream);
        String pattern = properties.getProperty("org.jamwiki.pattern");
        int limit = new Integer(properties.getProperty("org.jamwiki.limit")).intValue();
        int count = new Integer(properties.getProperty("org.jamwiki.count")).intValue();
        boolean append = Boolean.valueOf(properties.getProperty("org.jamwiki.append")).booleanValue();
        String datePattern = properties.getProperty("org.jamwiki.timestamp");
        DEFAULT_LOG_LEVEL = Level.parse(properties.getProperty("org.jamwiki.level"));
        WikiLogger.DEFAULT_LOG_HANDLER = new FileHandler(pattern, limit, count, append);
        DEFAULT_LOG_HANDLER.setFormatter(new WikiLogFormatter(datePattern));
        DEFAULT_LOG_HANDLER.setLevel(DEFAULT_LOG_LEVEL);
        // test the logger to verify permissions are OK
        Logger logger = Logger.getLogger(WikiLogger.class.getName());
        logger.addHandler(WikiLogger.DEFAULT_LOG_HANDLER);
        logger.setLevel(DEFAULT_LOG_LEVEL);
        logger.config("JAMWiki log initialized from " + propertyFile.getPath() + " with pattern " + pattern);
    } catch (Exception e) {
        System.out.println("WARNING: Unable to load custom JAMWiki logging configuration, using system default "
                + e.getMessage());
        WikiLogger.DEFAULT_LOG_HANDLER = null;
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (Exception ex) {
            }
        }
    }
}

From source file:org.ensembl.healthcheck.ConfigurableTestRunner.java

/**
 * Used for creating layered constructors.
 *//*from  ww  w . j av  a2 s  . c o m*/
protected static ConfigurationUserParameters createConfigurationObj(String[] args) {

    Logger logger = Logger.getLogger("ConfigurationUserParameters");
    // A temporary configuration object for accessing the command line
    // parameters in which the user configures where the configuration
    // files are located. Since only this information is of interest at
    // this point the configuration object is subcast to the
    // ConfigureConfiguration interface.
    //
    ConfigureConfiguration conf = new ConfigurationFactory<ConfigurationUserParameters>(
            ConfigurationUserParameters.class, (Object[]) args).getConfiguration(ConfigurationType.Commandline);

    // Get the list of property files the user specified and add the
    // default property file to it.
    //
    List<File> propertyFileNames = new ArrayList<File>();

    // The user is not required to provide a property file. In this case
    // only the
    // command line arguments and the default properties file will be used.
    //
    if (conf.isConf()) {
        propertyFileNames.addAll(conf.getConf());
    }
    propertyFileNames.add(new File(DEFAULT_PROPERTIES_FILE));

    // Use this to create the final configuration object.
    ConfigurationFactory<ConfigurationUserParameters> confFact = new ConfigurationFactory(
            ConfigurationUserParameters.class, args, propertyFileNames);

    // Users may want to know what went into the the configuration of this,
    // So some information on where the configuration information came
    // from is compiled here and sent to the logger.
    //
    StringBuffer msg = new StringBuffer();

    //
    // Create a few logging messages about the configuration information
    // that that will be used. Useful for debugging.
    //

    // Information about the command line arguments and which property files
    // are used
    msg.append("Creating configuration for this run.\n\n");
    msg.append("The following arguments were specified on the command line:\n");

    for (String arg : args) {
        if (arg.startsWith("-")) {
            msg.append("\n");
        }
        msg.append(" " + arg);
    }

    msg.append("\n\nThe following property files will be used:\n\n");

    for (File propertyFileName : propertyFileNames) {
        msg.append("  - " + propertyFileName.getName() + "\n");
    }

    logger.config(msg.toString());

    // Finally create the configuration object.
    ConfigurationUserParameters configuration = confFact.getConfiguration(ConfigurationType.Cascading);

    // Show user the final configuration settings that will be used.
    logger.config("The following settings will be used:\n\n"
            + new ConfigurationDumper<ConfigurationUserParameters>().dump(configuration));

    return configuration;
}

From source file:org.openconcerto.sql.PropsConfiguration.java

protected SQLServer createServer() {
    final String wanAddr = getProperty("server.wan.addr");
    final String wanPort = getProperty("server.wan.port");
    if (!hasWANProperties(wanAddr, wanPort))
        return doCreateServer();

    // if wanAddr is specified, always include it in ID, that way if we connect through the LAN
    // or through the WAN we have the same ID
    final String serverID = "tunnel to " + wanAddr + ":" + wanPort + " then " + getProperty("server.ip");
    final Logger log = Log.get();
    Exception origExn = null;//from  w w w .j  a va  2  s  .  co  m
    final SQLServer defaultServer;
    if (!"true".equals(getProperty("server.wan.only"))) {
        try {
            defaultServer = doCreateServer(serverID);
            // works since all ds params are provided by doCreateServer()
            defaultServer.getSystemRoot(getSystemRootName());
            // ok
            log.config("using " + defaultServer);

            return defaultServer;
        } catch (final RuntimeException e) {
            origExn = e;
            // on essaye par SSL
            log.config(e.getLocalizedMessage());
        }
        assert origExn != null;
    }
    this.openSSLConnection(wanAddr, Integer.valueOf(wanPort));
    this.isUsingSSH = true;
    log.info("ssl connection to " + this.conn.getHost() + ":" + this.conn.getPort());
    final int localPort = NetUtils.findFreePort(5436);
    try {
        // TODO add and use server.port
        final String[] serverAndPort = getProperty("server.ip").split(":");
        log.info("ssl tunnel from local port " + localPort + " to remote " + serverAndPort[0] + ":"
                + serverAndPort[1]);
        this.conn.setPortForwardingL(localPort, serverAndPort[0], Integer.valueOf(serverAndPort[1]));
    } catch (final Exception e1) {
        throw new IllegalStateException(
                "Impossible de crer la liaison scurise. Vrifier que le logiciel n'est pas dj lanc.",
                e1);
    }
    final SQLServer serverThruSSL = doCreateServer("localhost:" + localPort, null, serverID);
    try {
        serverThruSSL.getSystemRoot(getSystemRootName());
    } catch (final Exception e) {
        this.closeSSLConnection();
        throw new IllegalStateException("Couldn't connect through SSL : " + e.getLocalizedMessage(), origExn);
    }
    return serverThruSSL;

}

From source file:org.usrz.libs.logging.LevelDebugTest.java

@Test
public void testJavaLogging() {
    final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(this.getClass().getName());

    logger.finest("Foobar FINEST");
    AppenderForTests.hasNoLastEvent("at Finest level");
    assertFalse(logger.isLoggable(java.util.logging.Level.FINEST));

    logger.finer("Foobar FINER");
    AppenderForTests.hasNoLastEvent("at Finer level");
    assertFalse(logger.isLoggable(java.util.logging.Level.FINER));

    logger.fine("Foobar FINE");
    AppenderForTests.hasLastEvent("at Fine level");
    assertTrue(logger.isLoggable(java.util.logging.Level.FINE));

    logger.config("Foobar CONFIG");
    AppenderForTests.hasLastEvent("at Config level");
    assertTrue(logger.isLoggable(java.util.logging.Level.CONFIG));

    logger.info("Foobar INFO");
    AppenderForTests.hasLastEvent("at Info level");
    assertTrue(logger.isLoggable(java.util.logging.Level.INFO));

    logger.warning("Foobar WARNING");
    AppenderForTests.hasLastEvent("at Warning level");
    assertTrue(logger.isLoggable(java.util.logging.Level.WARNING));

    logger.severe("Foobar SEVERE");
    AppenderForTests.hasLastEvent("at Severe level");
    assertTrue(logger.isLoggable(java.util.logging.Level.SEVERE));

}

From source file:org.usrz.libs.logging.LevelErrorTest.java

@Test
public void testJavaLogging() {
    final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(this.getClass().getName());

    logger.finest("Foobar FINEST");
    AppenderForTests.hasNoLastEvent("at Finest level");
    assertFalse(logger.isLoggable(java.util.logging.Level.FINEST));

    logger.finer("Foobar FINER");
    AppenderForTests.hasNoLastEvent("at Finer level");
    assertFalse(logger.isLoggable(java.util.logging.Level.FINER));

    logger.fine("Foobar FINE");
    AppenderForTests.hasNoLastEvent("at Fine level");
    assertFalse(logger.isLoggable(java.util.logging.Level.FINE));

    logger.config("Foobar CONFIG");
    AppenderForTests.hasNoLastEvent("at Config level");
    assertFalse(logger.isLoggable(java.util.logging.Level.CONFIG));

    logger.info("Foobar INFO");
    AppenderForTests.hasNoLastEvent("at Info level");
    assertFalse(logger.isLoggable(java.util.logging.Level.INFO));

    logger.warning("Foobar WARNING");
    AppenderForTests.hasNoLastEvent("at Warning level");
    assertFalse(logger.isLoggable(java.util.logging.Level.WARNING));

    logger.severe("Foobar SEVERE");
    AppenderForTests.hasLastEvent("at Severe level");
    assertTrue(logger.isLoggable(java.util.logging.Level.SEVERE));

}

From source file:org.usrz.libs.logging.LevelInfoTest.java

@Test
public void testJavaLogging() {
    final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(this.getClass().getName());

    logger.finest("Foobar FINEST");
    AppenderForTests.hasNoLastEvent("at Finest level");
    assertFalse(logger.isLoggable(java.util.logging.Level.FINEST));

    logger.finer("Foobar FINER");
    AppenderForTests.hasNoLastEvent("at Finer level");
    assertFalse(logger.isLoggable(java.util.logging.Level.FINER));

    logger.fine("Foobar FINE");
    AppenderForTests.hasNoLastEvent("at Fine level");
    assertFalse(logger.isLoggable(java.util.logging.Level.FINE));

    logger.config("Foobar CONFIG");
    AppenderForTests.hasLastEvent("at Config level");
    assertTrue(logger.isLoggable(java.util.logging.Level.CONFIG));

    logger.info("Foobar INFO");
    AppenderForTests.hasLastEvent("at Info level");
    assertTrue(logger.isLoggable(java.util.logging.Level.INFO));

    logger.warning("Foobar WARNING");
    AppenderForTests.hasLastEvent("at Warning level");
    assertTrue(logger.isLoggable(java.util.logging.Level.WARNING));

    logger.severe("Foobar SEVERE");
    AppenderForTests.hasLastEvent("at Severe level");
    assertTrue(logger.isLoggable(java.util.logging.Level.SEVERE));

}

From source file:org.usrz.libs.logging.LevelTraceTest.java

@Test
public void testJavaLogging() {
    final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(this.getClass().getName());

    logger.finest("Foobar FINEST");
    AppenderForTests.hasLastEvent("at Finest level");
    assertTrue(logger.isLoggable(java.util.logging.Level.FINEST));

    logger.finer("Foobar FINER");
    AppenderForTests.hasLastEvent("at Finer level");
    assertTrue(logger.isLoggable(java.util.logging.Level.FINER));

    logger.fine("Foobar FINE");
    AppenderForTests.hasLastEvent("at Fine level");
    assertTrue(logger.isLoggable(java.util.logging.Level.FINE));

    logger.config("Foobar CONFIG");
    AppenderForTests.hasLastEvent("at Config level");
    assertTrue(logger.isLoggable(java.util.logging.Level.CONFIG));

    logger.info("Foobar INFO");
    AppenderForTests.hasLastEvent("at Info level");
    assertTrue(logger.isLoggable(java.util.logging.Level.INFO));

    logger.warning("Foobar WARNING");
    AppenderForTests.hasLastEvent("at Warning level");
    assertTrue(logger.isLoggable(java.util.logging.Level.WARNING));

    logger.severe("Foobar SEVERE");
    AppenderForTests.hasLastEvent("at Severe level");
    assertTrue(logger.isLoggable(java.util.logging.Level.SEVERE));

}