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:org.jenkinsci.remoting.protocol.ProtocolStackTest.java

@Test
public void stackCloseSequence() throws IOException {
    Logger logger = Logger.getLogger(ProtocolStack.class.getName());
    CapturingHandler handler = new CapturingHandler();
    assertThat(logger.isLoggable(Level.FINEST), is(false));
    Level oldLevel = logger.getLevel();
    logger.addHandler(handler);//from w  ww.j ava2  s  .c o  m
    try {
        logger.setLevel(Level.FINEST);
        assertThat(logger.isLoggable(Level.FINEST), is(true));

        final AtomicInteger state = new AtomicInteger();
        ProtocolStack.on(new NetworkLayer(selector) {

            @Override
            public void start() throws IOException {
            }

            @Override
            protected void write(@NonNull ByteBuffer data) throws IOException {

            }

            @Override
            public void doCloseRecv() {
                state.compareAndSet(3, 4);
                onRecvClosed();

            }

            @Override
            public void doCloseSend() throws IOException {
                state.compareAndSet(2, 3);
                doCloseRecv();
            }

            @Override
            public boolean isSendOpen() {
                return true;
            }

        }).filter(new FilterLayer() {
            @Override
            public void start() throws IOException {
            }

            @Override
            public void onRecv(@NonNull ByteBuffer data) throws IOException {

            }

            @Override
            public void doSend(@NonNull ByteBuffer data) throws IOException {

            }

            @Override
            public void doCloseSend() throws IOException {
                state.compareAndSet(1, 2);
                super.doCloseSend();
            }

            @Override
            public void onRecvClosed(IOException cause) throws IOException {
                state.compareAndSet(4, 5);
                super.onRecvClosed(cause);
            }
        }).filter(new FilterLayer() {
            @Override
            public void start() throws IOException {
            }

            @Override
            public void onRecv(@NonNull ByteBuffer data) throws IOException {

            }

            @Override
            public void doSend(@NonNull ByteBuffer data) throws IOException {

            }

            @Override
            public void doCloseSend() throws IOException {
                state.compareAndSet(0, 1);
                super.doCloseSend();
            }

            @Override
            public void onRecvClosed(IOException cause) throws IOException {
                state.compareAndSet(5, 6);
                super.onRecvClosed(cause);
            }
        }).named("closeSeq").build(new ApplicationLayer<Void>() {
            @Override
            public boolean isReadOpen() {
                return true;
            }

            @Override
            public void onRead(@NonNull ByteBuffer data) throws IOException {

            }

            @Override
            public Void get() {
                return null;
            }

            @Override
            public void start() throws IOException {
            }

            @Override
            public void onReadClosed(IOException cause) throws IOException {
                state.compareAndSet(6, 7);
            }

        }).close();
        assertThat("Close in sequence", state.get(), is(7));
        assertThat(handler.logRecords,
                contains(
                        allOf(hasProperty("message", is("[{0}] Initializing")),
                                hasProperty("parameters", is(new Object[] { "closeSeq" }))),
                        allOf(hasProperty("message", is("[{0}] Starting")),
                                hasProperty("parameters", is(new Object[] { "closeSeq" }))),
                        allOf(hasProperty("message", is("[{0}] Started")),
                                hasProperty("parameters", is(new Object[] { "closeSeq" }))),
                        allOf(hasProperty("message", is("[{0}] Closing")),
                                hasProperty("parameters", is(new Object[] { "closeSeq" }))),
                        allOf(hasProperty("message", is("[{0}] Closed")),
                                hasProperty("parameters", is(new Object[] { "closeSeq" })))));
    } finally {
        logger.removeHandler(handler);
        logger.setLevel(oldLevel);
    }
}

From source file:com.timemachine.controller.ControllerActivity.java

private void setupSocketConnection(String text) {
    socket = null;//from  www. java2s  .  co  m

    try {
        socket = new SocketIO("http://" + text + ":8080/controller");
        // Set the log level
        final Logger logger = Logger.getLogger("io.socket");
        logger.setLevel(Level.WARNING);
        //logger.setLevel(Level.ALL);
    } catch (MalformedURLException e1) {
        e1.printStackTrace();
        System.out.println("SocketConnection not initialized..!!");
        showConnectDialog("Error while setting up sockets. Connect again.");
    }

    socket.connect(new IOCallback() {
        @Override
        public void onMessage(JSONObject json, IOAcknowledge ack) {
            try {
                System.out.println("Server said:" + json.toString(2));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onMessage(String data, IOAcknowledge ack) {
            try {
                System.out.println("Server said: " + data);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onError(SocketIOException socketIOException) {
            System.out.println("an Error occured");
            socketIOException.printStackTrace();
            showConnectDialog("Error connecting to server. Connect again.");
        }

        @Override
        public void onDisconnect() {
            System.out.println("Connection terminated.");
        }

        @Override
        public void onConnect() {
            System.out.println("Connection established");
            isMasterConnected = false;
            runOnUiThread(new Runnable() {
                public void run() {
                    processDialog.dismiss();
                    if (!isContentViewExist) {
                        isContentViewExist = true;
                        setContentView(R.layout.activity_controller);
                    }
                    setupUI();
                }
            });
        }

        @Override
        public void on(String event, IOAcknowledge ack, Object... args) {
            if (event.equals("sync handlePlayPauseController")) {
                handlePlayPauseUI((Boolean) args[0]);
            }
        }
    });
}

From source file:com.ellychou.todo.rest.service.SpringContextJerseyTest.java

/**
* Register {@link Handler log handler} to the list of root loggers.
*//* w ww . ja va 2 s.  c om*/
private void registerLogHandler() {
    final String recordLogLevel = getProperty(TestProperties.RECORD_LOG_LEVEL);
    final int recordLogLevelInt = Integer.valueOf(recordLogLevel);
    final Level level = Level.parse(recordLogLevel);

    logLevelMap.clear();

    for (final Logger root : getRootLoggers()) {
        logLevelMap.put(root, root.getLevel());

        if (root.getLevel().intValue() > recordLogLevelInt) {
            root.setLevel(level);
        }

        root.addHandler(getLogHandler());
    }
}

From source file:es.upm.dit.gsi.sim.twitter.TwitterSimulation.java

/**
 * Constructor//from w  w w.  ja v a 2 s  . c  om
 * 
 * @param seed
 */
public TwitterSimulation(long seed, List<String> topics) {
    super(seed);
    Logger globalLogger = logger.getParent();
    globalLogger.setLevel(level);
    for (Handler handler : globalLogger.getHandlers()) {
        handler.setLevel(level);
    }
    this.topicManager = new TopicManager();
    this.topicManager.setTopics(topics);
}

From source file:es.upm.dit.gsi.sim.twitter.TwitterSimulation.java

/**
 * @param seed/*from www .  j  av  a  2 s.c  o  m*/
 * @param network
 */
public TwitterSimulation(long seed, Network network, List<String> topics) {
    super(seed);
    Logger globalLogger = logger.getParent();
    globalLogger.setLevel(level);
    for (Handler handler : globalLogger.getHandlers()) {
        handler.setLevel(level);
    }
    this.topicManager = new TopicManager();
    this.topicManager.setTopics(topics);
    this.initialNetwork = network;
    this.loadInitialNetwork = true;
}

From source file:com.googlecode.jgenhtml.Config.java

/**
 * Load command line args and config file properties into this config instance and reconfigure as appropriate.
 * @param argv Command line args./*from  w ww . j ava  2 s  .  com*/
 * @throws ParseException
 */
public void initializeUserPrefs(String[] argv) throws ParseException {
    CommandLineParser parser = new PosixParser();
    CommandLine cmd = parser.parse(options, argv);

    if (cmd.hasOption(CmdLineArg.HELP.toString())) {
        this.help = true;
    } else if (cmd.hasOption(CmdLineArg.VERSION.toString())) {
        this.version = true;
    } else {
        if (cmd.hasOption(Config.CmdLineArg.QUIET.toString())) {
            this.quiet = true;
            Logger parent = Logger.getLogger("com.googlecode.jgenhtml");
            parent.setLevel(Level.WARNING);
        }
        if (cmd.hasOption(CmdLineArg.SHOW_DETAILS.toString())) {
            this.setShowDetails(true);
        }
        if (cmd.hasOption(CmdLineArg.OUTPUT.toString())) {
            this.setOutRootDir(cmd.getOptionValue(CmdLineArg.OUTPUT.toString()));
        }
        if (cmd.hasOption(CmdLineArg.TITLE.toString())) {
            this.setTitle(cmd.getOptionValue(CmdLineArg.TITLE.toString()));
        }
        if (cmd.hasOption(CmdLineArg.CSS.toString())) {
            this.setCssFile(cmd.getOptionValue(CmdLineArg.CSS.toString()));
        }
        if (cmd.hasOption(CmdLineArg.DESCFILE.toString())) {
            this.setDescFile(cmd.getOptionValue(CmdLineArg.DESCFILE.toString()));
        }
        if (cmd.hasOption(CmdLineArg.BASEFILE.toString())) {
            this.setBaseFile(cmd.getOptionValue(CmdLineArg.BASEFILE.toString()));
        }
        if (cmd.hasOption(CmdLineArg.KEEPDESC.toString())) {
            this.setKeepDescriptions(true);
        }
        if (cmd.hasOption(CmdLineArg.SPACES.toString())) {
            this.setNumSpaces(cmd.getOptionValue(CmdLineArg.SPACES.toString()));
        }
        if (cmd.hasOption(CmdLineArg.NOSOURCE.toString())) {
            this.setNoSource(true);
        }
        if (cmd.hasOption(CmdLineArg.GZIP.toString())) {
            this.setGzip(true);
        }
        if (cmd.hasOption(CmdLineArg.NOSORT.toString())) {
            this.setNoSort(true);
        } else if (cmd.hasOption(CmdLineArg.SORT.toString())) {
            this.setNoSort(false);//wow, this is totally pointless
        }
        if (cmd.hasOption(CmdLineArg.LEGEND.toString())) {
            this.setLegend(true);
        }
        if (cmd.hasOption(CmdLineArg.HTML_EXT.toString())) {
            this.setHtmlExt(cmd.getOptionValue(CmdLineArg.HTML_EXT.toString()));
        }
        if (cmd.hasOption(CmdLineArg.NOFUNCOV.toString())) {
            this.setFunctionCoverage(false);
        } else if (cmd.hasOption(CmdLineArg.FUNCOV.toString())) {
            this.setFunctionCoverage(true);
        }
        if (cmd.hasOption(CmdLineArg.NOBRANCOV.toString())) {
            this.setBranchCoverage(false);
        } else if (cmd.hasOption(CmdLineArg.BRANCOV.toString())) {
            this.setBranchCoverage(true);
        }
        if (cmd.hasOption(CmdLineArg.NOPREFIX.toString())) {
            this.setNoPrefix(true);
        } else if (cmd.hasOption(CmdLineArg.PREFIX.toString())) {
            this.setPrefix(cmd.getOptionValue(CmdLineArg.PREFIX.toString()));
        }
        traceFiles = cmd.getArgs();
        if (traceFiles != null && traceFiles.length > 0) {
            this.loadConfigFile(cmd.getOptionValue(CmdLineArg.CONFFILE.toString()));
        }
    }
}

From source file:org.jenkinsci.maven.plugins.hpi.RunMojo.java

public void execute() throws MojoExecutionException, MojoFailureException {
    getProject().setArtifacts(resolveDependencies(dependencyResolution));

    File basedir = getProject().getBasedir();

    if (webApp == null || webApp.getContextPath() == null) {
        if (contextPath != null) {
            getLog().warn(/*w  w  w .  j  av a2s . c  o  m*/
                    "Please use `webApp/contextPath` configuration parameter in place of the deprecated `contextPath` parameter");
            if (webApp == null) {
                try {
                    webApp = new JettyWebAppContext();
                } catch (Exception e) {
                    throw new MojoExecutionException("Failed to initialize webApp configuration", e);
                }
            }
            webApp.setContextPath(contextPath);
        }
    }

    // compute jenkinsHome
    if (jenkinsHome == null) {
        if (hudsonHome != null) {
            getLog().warn(
                    "Please use the `jenkinsHome` configuration parameter in place of the deprecated `hudsonHome` parameter");
            jenkinsHome = hudsonHome;
        }
        String h = System.getenv("JENKINS_HOME");
        if (h == null) {
            h = System.getenv("HUDSON_HOME");
        }
        if (h != null)
            jenkinsHome = new File(h);
        else
            jenkinsHome = new File(basedir, "work");
    }

    // auto-enable stapler trace, unless otherwise configured already.
    setSystemPropertyIfEmpty("stapler.trace", "true");
    // allow Jetty to accept a bigger form so that it can handle update center JSON post
    setSystemPropertyIfEmpty("org.eclipse.jetty.Request.maxFormContentSize", "-1");
    // general-purpose system property so that we can tell from Jenkins if we are running in the hpi:run mode.
    setSystemPropertyIfEmpty("hudson.hpi.run", "true");
    // this adds 3 secs to the shutdown time. Skip it.
    setSystemPropertyIfEmpty("hudson.DNSMultiCast.disabled", "true");
    // expose the current top-directory of the plugin
    setSystemPropertyIfEmpty("jenkins.moduleRoot", basedir.getAbsolutePath());

    if (systemProperties != null && !systemProperties.isEmpty()) {
        for (Map.Entry<String, String> entry : systemProperties.entrySet()) {
            if (entry.getKey() != null && entry.getValue() != null) {
                System.setProperty(entry.getKey(), entry.getValue());
            }
        }
    }

    // look for jenkins.war
    Artifacts jenkinsArtifacts = Artifacts.of(getProject())
            .groupIdIs("org.jenkins-ci.main", "org.jvnet.hudson.main").artifactIdIsNot("remoting"); // remoting moved to its own release cycle

    webAppFile = getJenkinsWarArtifact().getFile();

    // make sure all the relevant Jenkins artifacts have the same version
    for (Artifact a : jenkinsArtifacts) {
        Artifact ba = jenkinsArtifacts.get(0);
        if (!a.getVersion().equals(ba.getVersion()))
            throw new MojoExecutionException("Version of " + a.getId() + " is inconsistent with " + ba.getId());
    }

    // set JENKINS_HOME
    setSystemPropertyIfEmpty("JENKINS_HOME", jenkinsHome.getAbsolutePath());
    File pluginsDir = new File(jenkinsHome, "plugins");
    pluginsDir.mkdirs();

    // enable view auto refreshing via stapler
    setSystemPropertyIfEmpty("stapler.jelly.noCache", "true");

    List<Resource> res = getProject().getBuild().getResources();
    if (!res.isEmpty()) {
        // pick up the first one and use it
        Resource r = res.get(0);
        setSystemPropertyIfEmpty("stapler.resourcePath", r.getDirectory());
    }

    generateHpl();

    // copy other dependency Jenkins plugins
    try {
        for (MavenArtifact a : getProjectArtifacts()) {
            if (!a.isPlugin())
                continue;

            // find corresponding .hpi file
            Artifact hpi = artifactFactory.createArtifact(a.getGroupId(), a.getArtifactId(), a.getVersion(),
                    null, "hpi");
            artifactResolver.resolve(hpi, getProject().getRemoteArtifactRepositories(), localRepository);

            // check recursive dependency. this is a rare case that happens when we split out some things from the core
            // into a plugin
            if (hasSameGavAsProject(hpi))
                continue;

            if (hpi.getFile().isDirectory())
                throw new UnsupportedOperationException(
                        hpi.getFile() + " is a directory and not packaged yet. this isn't supported");

            File upstreamHpl = pluginWorkspaceMap.read(hpi.getId());
            if (upstreamHpl != null) {
                copyHpl(upstreamHpl, pluginsDir, a.getActualArtifactId());
            } else {
                copyPlugin(hpi.getFile(), pluginsDir, a.getActualArtifactId());
            }
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to copy dependency plugin", e);
    } catch (ArtifactNotFoundException e) {
        throw new MojoExecutionException("Unable to copy dependency plugin", e);
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException("Unable to copy dependency plugin", e);
    }

    if (loggers != null) {
        for (Handler h : LogManager.getLogManager().getLogger("").getHandlers()) {
            if (h instanceof ConsoleHandler) {
                h.setLevel(Level.ALL);
            }
        }
        loggerReferences = new LinkedList<Logger>();
        for (Map.Entry<String, String> logger : loggers.entrySet()) {
            Logger l = Logger.getLogger(logger.getKey());
            loggerReferences.add(l);
            l.setLevel(Level.parse(logger.getValue()));
        }
    }

    super.execute();
}

From source file:com.googlecode.jgenhtml.Config.java

/**
* Loads the lcovrc config file from the home directory or the location specified on the
* command line and sets properties in the config object accordingly.
* Does not look for a system wide config file because there is no consistent directory to
* look in across all platforms./*  w w  w.j  a va 2  s . c  om*/
*
* @param alternatePath
*/
private void loadConfigFile(final String alternatePath) {
    try {
        //don't use FileUtils.getUserDirectoryPath() here, it was causing issues when run from Ant
        String lcovrc = System.getProperty("user.home") + File.separatorChar + ".lcovrc";
        Properties properties = loadFileToProperties(alternatePath);
        if (properties != null || (properties = loadFileToProperties(lcovrc)) != null) {

            LOGGER.log(Level.INFO, "Loaded config file {0}.", lcovrc);
            if (properties.containsKey(ConfFileArg.CSS.toString())) {
                setCssFile(properties.getProperty(ConfFileArg.CSS.toString()));
            }
            Integer optionValue = getNumericValue(properties, ConfFileArg.FUNCOV.toString());
            if (optionValue != null) {
                setFunctionCoverage(optionValue != 0);
            }
            optionValue = getNumericValue(properties, ConfFileArg.BRANCOV.toString());
            if (optionValue != null) {
                setBranchCoverage(optionValue != 0);
            }
            optionValue = getNumericValue(properties, ConfFileArg.GZIP.toString());
            if (optionValue != null) {
                setGzip(optionValue != 0);
            }
            optionValue = getNumericValue(properties, ConfFileArg.KEEPDESC.toString());
            if (optionValue != null) {
                setKeepDescriptions(optionValue != 0);
            }
            optionValue = getNumericValue(properties, ConfFileArg.NOSOURCE.toString());
            if (optionValue != null) {
                setNoSource(optionValue != 0);
            }
            optionValue = getNumericValue(properties, ConfFileArg.SORT.toString());
            if (optionValue != null) {
                setNoSort(optionValue == 0);
            }
            optionValue = getNumericValue(properties, ConfFileArg.SPACES.toString());
            if (optionValue != null) {
                setNumSpaces(optionValue);
            }
            optionValue = getNumericValue(properties, ConfFileArg.HILIMIT.toString());
            if (optionValue != null) {
                setHiLimit(optionValue);
            }
            optionValue = getNumericValue(properties, ConfFileArg.MEDLIMIT.toString());
            if (optionValue != null) {
                setMedLimit(optionValue);
            }
            optionValue = getNumericValue(properties, ConfFileArg.NOPREFIX.toString());
            if (optionValue != null) {
                setNoPrefix(optionValue != 0);
            }
            optionValue = getNumericValue(properties, ConfFileArg.LEGEND.toString());
            if (optionValue != null) {
                setLegend(optionValue != 0);
            }
            if (properties.containsKey(ConfFileArg.HTML_EXT.toString())) {
                setHtmlExt(properties.getProperty(ConfFileArg.HTML_EXT.toString()));
            }
            optionValue = getNumericValue(properties, ConfFileArg.HTMLONLY.toString());
            if (optionValue != null) {
                setHtmlOnly(optionValue != 0);
            }
            optionValue = getNumericValue(properties, ConfFileArg.VERBOSE.toString());
            if (optionValue != null) {
                if (optionValue != 0) {
                    Logger parent = Logger.getLogger("com.googlecode.jgenhtml");
                    parent.setLevel(Level.ALL);
                }
            }
        }
    } catch (IOException ex) {
        LOGGER.log(Level.WARNING, ex.getLocalizedMessage());
    }
}

From source file:name.livitski.databag.cli.Launcher.java

protected void setLogLevel(Level level) {
    Logger root = Logger.getLogger("");
    root.setLevel(level);
}

From source file:processing.app.Base.java

static public void initLogger() {
    Handler consoleHandler = new ConsoleLogger();
    consoleHandler.setLevel(Level.ALL);
    consoleHandler.setFormatter(new LogFormatter("%1$tl:%1$tM:%1$tS [%4$7s] %2$s: %5$s%n"));

    Logger globalLogger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
    globalLogger.setLevel(consoleHandler.getLevel());

    // Remove default
    Handler[] handlers = globalLogger.getHandlers();
    for (Handler handler : handlers) {
        globalLogger.removeHandler(handler);
    }/*from   w ww  .j av a2 s. co m*/
    Logger root = Logger.getLogger("");
    handlers = root.getHandlers();
    for (Handler handler : handlers) {
        root.removeHandler(handler);
    }

    globalLogger.addHandler(consoleHandler);

    Logger.getLogger("cc.arduino.packages.autocomplete").setParent(globalLogger);
    Logger.getLogger("br.com.criativasoft.cpluslibparser").setParent(globalLogger);
    Logger.getLogger(Base.class.getPackage().getName()).setParent(globalLogger);

}