Example usage for java.util.logging Logger setLevel

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

Introduction

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

Prototype

public void setLevel(Level newLevel) throws SecurityException 

Source Link

Document

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

Usage

From source file:app.logica.gestores.GestorEmail.java

public GestorEmail() {
    final java.util.logging.Logger buggyLogger = java.util.logging.Logger
            .getLogger(FileDataStoreFactory.class.getName());
    buggyLogger.setLevel(java.util.logging.Level.SEVERE);

    try {/*from  ww w .ja v  a 2s  . c o m*/
        HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
        DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

From source file:org.deviceconnect.android.deviceplugin.theta.ThetaDeviceApplication.java

@Override
public void onCreate() {
    super.onCreate();

    if (BuildConfig.DEBUG) {
        for (Logger logger : mLoggers) {
            AndroidHandler handler = new AndroidHandler(logger.getName());
            handler.setFormatter(new SimpleFormatter());
            handler.setLevel(Level.ALL);
            logger.addHandler(handler);//  ww w .  j a  v  a2s .  c  om
            logger.setLevel(Level.ALL);
        }
    } else {
        for (Logger logger : mLoggers) {
            logger.setLevel(Level.OFF);
        }
    }

    Context context = getApplicationContext();
    mDeviceMgr = new ThetaDeviceManager(context);
    mHeadTracker = new HeadTrackerWrapper(new DefaultHeadTracker(context));
    mSphericalViewApi = new SphericalViewApi(context);
}

From source file:bookkeepr.BookKeepr.java

/**
 * This loads the configuration file and sets the intial settings. 
 *//*from   ww w.  j av a2s  . c  o m*/
public BookKeepr(File configFile) {

    try {
        this.configFile = configFile;
        if (!configFile.exists()) {
            config = new BookkeeprConfig();
            config.setOriginId(0);
            saveConfig();
        }
        config = (BookkeeprConfig) XMLReader.read(new FileInputStream(configFile));
        if (config.getOriginId() < 0 || config.getOriginId() > 255) {
            config.setOriginId(0);

        }
        if (config.getOriginId() == 0) {
            Logger.getLogger(BookKeepr.class.getName()).log(Level.INFO,
                    "Client mode active, creation or modification disabled");
        }

        statusMon = new BookKeeprStatusMonitor();
        Logger logger = Logger.getLogger("bookkeepr");
        logger.setLevel(Level.ALL);
        logger.setUseParentHandlers(false);
        logger.addHandler(statusMon);
    } catch (SAXException ex) {
        Logger.getLogger(BookKeepr.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(BookKeepr.class.getName()).log(Level.SEVERE, null, ex);
    }
    for (int i = 0; i < 20; i++) {
        HttpClient httpclient = new DefaultHttpClient();
        HttpClientParams.setRedirecting(httpclient.getParams(), false);
        HttpConnectionParams.setConnectionTimeout(httpclient.getParams(), 10000);
        if (config.getProxyUrl() != null) {
            final HttpHost proxy = new HttpHost(config.getProxyUrl(), config.getProxyPort(), "http");
            httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        }
        httpClients.add(httpclient);
    }

}

From source file:mockit.integration.logging.LoggingIntegrationsTest.java

@Test
public void jdkLoggingShouldLogNothing() {
    Logger log1 = Logger.getAnonymousLogger();
    Logger log2 = Logger.getAnonymousLogger("bundle");
    Logger log3 = Logger.getLogger(LoggingIntegrationsTest.class.getName());
    Logger log4 = Logger.getLogger(LoggingIntegrationsTest.class.getName(), "bundle");

    assertFalse(log1.isLoggable(Level.ALL));
    log1.severe("testing that logger does nothing");
    log2.setLevel(Level.WARNING);
    log2.info("testing that logger does nothing");
    log3.warning("testing that logger does nothing");
    log4.fine("testing that logger does nothing");
    log4.finest("testing that logger does nothing");
}

From source file:de.crowdcode.kissmda.maven.plugin.KissMdaMojo.java

private void setLoggingLevel() {
    Logger log = LogManager.getLogManager().getLogger("");

    if (loggingLevel == null || loggingLevel.equals("")) {
        log.setLevel(Level.INFO);
    } else {/*from w w  w .  j a  va  2  s.  c  o m*/
        log.setLevel(loggingLevelMapper.getLevel(loggingLevel));
    }

    for (Handler handler : log.getHandlers()) {
        if (loggingLevel == null || loggingLevel.equals("")) {
            handler.setLevel(Level.INFO);
        } else {
            handler.setLevel(loggingLevelMapper.getLevel(loggingLevel));
        }
    }
}

From source file:mockit.integration.logging.LoggingIntegrationsTest.java

@Test
public void log4jShouldLogNothing() {
    org.apache.log4j.Logger log1 = org.apache.log4j.Logger.getLogger("test");
    org.apache.log4j.Logger log2 = org.apache.log4j.Logger.getLogger(LoggingIntegrationsTest.class);
    org.apache.log4j.Logger log3 = org.apache.log4j.Logger.getLogger("test", null);
    org.apache.log4j.Logger log4 = org.apache.log4j.Logger.getRootLogger();

    assertFalse(log1.isTraceEnabled());//w w  w  .  j a v  a 2  s .  c  o  m
    log1.error("testing that log4j does nothing");
    log2.setLevel(org.apache.log4j.Level.FATAL);
    log2.debug("testing that log4j does nothing");
    log3.fatal("testing that log4j does nothing");
    log4.info("testing that log4j does nothing");
}

From source file:org.ejbca.ui.tcp.CmpTcpServer.java

public void start() throws UnknownHostException {
    final String cmdHandle = org.ejbca.ui.tcp.CmpTcpCommandHandler.class.getName();

    myServer = new QuickServer();
    myServer.setClientAuthenticationHandler(null);
    myServer.setBindAddr(CmpTcpConfiguration.getTCPBindAdress());
    myServer.setPort(CmpTcpConfiguration.getTCPPortNumber());
    myServer.setName("CMP TCP Server v " + VER);
    if (QuickServer.getVersionNo() >= 1.2) {
        LOG.info("Using 1.2 feature");
        myServer.setClientBinaryHandler(cmdHandle);
        myServer.setClientEventHandler(cmdHandle);

        //reduce info to Console
        myServer.setConsoleLoggingToMicro();
    }//  w w w.  java 2 s  .  c o m

    //setup logger to log to file
    Logger logger = null;
    FileHandler txtLog = null;
    final String logDir = CmpTcpConfiguration.getTCPLogDir();
    final File logFile = new File(logDir + "/");
    if (!logFile.canRead()) {
        logFile.mkdir();
    }
    try {
        logger = Logger.getLogger("");
        logger.setLevel(Level.INFO);

        logger = Logger.getLogger("cmptcpserver");
        logger.setLevel(Level.FINEST);
        txtLog = new FileHandler(logDir + "/cmptcpserver.log");
        //reduce info 
        txtLog.setFormatter(new org.quickserver.util.logging.MicroFormatter());
        logger.addHandler(txtLog);

        myServer.setAppLogger(logger); //imp

        //myServer.setConsoleLoggingToMicro();
        myServer.setConsoleLoggingFormatter("org.quickserver.util.logging.SimpleTextFormatter");
        myServer.setConsoleLoggingLevel(Level.INFO);
    } catch (Exception e) {
        LOG.error("Could not create xmlLog FileHandler : ", e);
    }
    try {
        final String confFile = CmpTcpConfiguration.getTCPConfigFile();
        if (!StringUtils.isEmpty(confFile)) {
            final Object config[] = new Object[] { confFile };
            if (!myServer.initService(config)) {
                LOG.error("Configuration from config file " + confFile + " failed!");
            }
        }
        myServer.startServer();
        //myServer.getQSAdminServer().setShellEnable(true);
        //myServer.startQSAdminServer();         
    } catch (AppException e) {
        LOG.error("Error in server : ", e);
    }
}

From source file:com.googlecode.fightinglayoutbugs.FightingLayoutBugs.java

private void setLogLevelToDebug() {
    String name = FightingLayoutBugs.class.getPackage().getName();
    final Log log = LogFactory.getLog(name);
    if (log instanceof Jdk14Logger || (log instanceof AvalonLogger
            && ((AvalonLogger) log).getLogger() instanceof org.apache.avalon.framework.logger.Jdk14Logger)) {
        final Logger logger = Logger.getLogger(name);
        final Level originalLevel = logger.getLevel();
        logger.setLevel(Level.FINE);
        _runAfterAnalysis.add(new Runnable() {
            @Override//from  ww  w .  j a v a 2 s  .  c  o m
            public void run() {
                logger.setLevel(originalLevel);
            }
        });
        enableDebugOutputToConsole(logger);
    } else if (log instanceof Log4JLogger || (log instanceof AvalonLogger
            && ((AvalonLogger) log).getLogger() instanceof org.apache.avalon.framework.logger.Log4JLogger)) {
        final org.apache.log4j.Logger logger = LogManager.getLogger(name);
        final org.apache.log4j.Level originalLevel = logger.getLevel();
        logger.setLevel(org.apache.log4j.Level.DEBUG);
        _runAfterAnalysis.add(new Runnable() {
            @Override
            public void run() {
                logger.setLevel(originalLevel);
            }
        });
    } else if (log instanceof LogKitLogger || (log instanceof AvalonLogger
            && ((AvalonLogger) log).getLogger() instanceof org.apache.avalon.framework.logger.LogKitLogger)) {
        final org.apache.log.Logger logger = LogKit.getLoggerFor(name);
        final Priority originalLevel = logger.getPriority();
        logger.setPriority(Priority.DEBUG);
        _runAfterAnalysis.add(new Runnable() {
            @Override
            public void run() {
                logger.setPriority(originalLevel);
            }
        });
    } else if (log instanceof SimpleLog) {
        final SimpleLog simpleLog = (SimpleLog) log;
        final int originalLevel = simpleLog.getLevel();
        simpleLog.setLevel(SimpleLog.LOG_LEVEL_DEBUG);
        _runAfterAnalysis.add(new Runnable() {
            @Override
            public void run() {
                simpleLog.setLevel(originalLevel);
            }
        });
    }
}

From source file:org.shaman.database.Benchmark.java

@Test
public void benchmark() throws IOException, ClassNotFoundException {
    //disable logger
    Logger logger = Logger.getLogger("org.shaman.database");
    Level oldLevel = logger.getLevel();
    logger.setLevel(Level.OFF);

    System.out.println("Benchmark");
    long seed = System.currentTimeMillis();
    Random rand = new Random(seed);
    //to reproduce the same results, set seed to another value
    System.out.println("seed: " + seed);

    //description
    System.out.println("This benchmark generates 9 different test record graphs,\n"
            + "3 with few but huge entities, 2 with many empty entites and 4 with a complex scene");
    System.out.println("It tests these cases:");
    System.out.println("1. The file size when saved with the databse, the default java serialization,\n"
            + "   the java serialization gzip-compressed and java-beans xml output");
    System.out.println("2. The time to save and load the scene using the database, the java serialization,\n"
            + "   the java serialization gzip-compressed and java-beans xml output");
    System.out.println(/*from w  ww  . j  a v  a 2  s. com*/
            "in the last case, the output streams are buffered using BufferedInputStream / BufferedOutputStream\n"
                    + "and the database uses the default io as used when not excplizit specified");
    System.out.println();

    //generate scenes
    Record[] scenes = new Record[] { generateScene1(rand), generateScene1(rand), generateScene1(rand),
            generateScene2(rand), generateScene2(rand), generateScene3(rand), generateScene3(rand),
            generateScene3(rand), generateScene3(rand) };

    try {
        //file size
        System.out.println("file size:");
        printFileSizes(scenes);

        //save/load times
        printSaveLoadTimes(scenes);
    } finally {
        logger.setLevel(oldLevel);
    }
}

From source file:org.mp4parser.tools.Main.java

public Logger setupLogger() {
    Logger logger = Logger.getLogger("tools");
    InputStream stream;//from   w ww . j a v  a 2s . c o  m
    if (verbose) {
        stream = Main.class.getResourceAsStream("/log-verbose.properties");
    } else {
        stream = Main.class.getResourceAsStream("/log.properties");
    }
    try {
        LogManager.getLogManager().readConfiguration(stream);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    logger.setLevel(Level.FINE);
    logger.addHandler(new java.util.logging.ConsoleHandler());
    logger.setUseParentHandlers(false);

    return logger;
}