Example usage for java.util.logging Logger getLevel

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

Introduction

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

Prototype

public Level getLevel() 

Source Link

Document

Get the log Level that has been specified for this Logger.

Usage

From source file:org.geoserver.config.ServicePersisterTest.java

@Test
public void testRemoveWorkspaceLocalService() throws Exception {
    testAddWorkspaceLocalService();//from   w  w  w.j a  v  a2s  .  c o m

    File dataDirRoot = getTestData().getDataDirectoryRoot();
    WorkspaceInfo ws = getCatalog().getDefaultWorkspace();

    File f = new File(dataDirRoot, "workspaces" + "/" + ws.getName() + "/service.xml");
    assertTrue(f.exists());

    Logger logger = Logging.getLogger(GeoServerImpl.class);
    Level level = logger.getLevel();
    try {
        logger.setLevel(Level.OFF);
        ServiceInfo s = geoServer.getServiceByName(ws, "foo", ServiceInfo.class);
        geoServer.remove(s);
        assertFalse(f.exists());
    } finally {
        logger.setLevel(level);
    }
}

From source file:org.jenkinsci.remoting.protocol.ProtocolStackTest.java

@Test
public void initSequence() 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 ww w . j  ava  2  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
            protected void write(@NonNull ByteBuffer data) throws IOException {

            }

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

            @Override
            public void doCloseSend() throws IOException {

            }

            @Override
            public void doCloseRecv() {

            }

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

        }).filter(new FilterLayer() {
            @Override
            public void start() throws IOException {
                state.compareAndSet(1, 2);
            }

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

            }

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

            }

        }).filter(new FilterLayer() {
            @Override
            public void start() throws IOException {
                state.compareAndSet(2, 3);
            }

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

            }

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

            }

        }).named("initSeq").build(new ApplicationLayer<Void>() {
            @Override
            public Void get() {
                return null;
            }

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

            }

            @Override
            public void start() throws IOException {
                state.compareAndSet(3, 4);
            }

            @Override
            public void onReadClosed(IOException cause) throws IOException {

            }

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

        });
        assertThat("Init in sequence", state.get(), is(4));
        assertThat(handler.logRecords,
                contains(
                        allOf(hasProperty("message", is("[{0}] Initializing")),
                                hasProperty("parameters", is(new Object[] { "initSeq" }))),
                        allOf(hasProperty("message", is("[{0}] Starting")),
                                hasProperty("parameters", is(new Object[] { "initSeq" }))),
                        allOf(hasProperty("message", is("[{0}] Started")),
                                hasProperty("parameters", is(new Object[] { "initSeq" })))));
    } finally {
        logger.removeHandler(handler);
        logger.setLevel(oldLevel);
    }
}

From source file:org.jenkinsci.remoting.protocol.ProtocolStackTest.java

@Test
public void initSequenceFailure() 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  www .  j  a va  2 s .c o  m*/
    try {
        logger.setLevel(Level.FINEST);
        assertThat(logger.isLoggable(Level.FINEST), is(true));
        final AtomicInteger state = new AtomicInteger();
        try {
            ProtocolStack.on(new NetworkLayer(selector) {

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

                }

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

                @Override
                public void doCloseSend() throws IOException {

                }

                @Override
                public void doCloseRecv() {

                }

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

            }).filter(new FilterLayer() {
                @Override
                public void start() throws IOException {
                    state.compareAndSet(1, 2);
                    throw new IOException("boom");
                }

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

                }

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

                }

            }).filter(new FilterLayer() {
                @Override
                public void start() throws IOException {
                    state.set(-2);
                }

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

                }

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

                }

                @Override
                public void onRecvClosed(IOException cause) throws IOException {
                    state.compareAndSet(2, 3);
                    super.onRecvClosed(cause);
                }
            }).named("initSeq").build(new ApplicationLayer<Void>() {
                @Override
                public Void get() {
                    return null;
                }

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

                }

                @Override
                public void start() throws IOException {
                    state.set(-3);
                }

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

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

            });
            fail("Expecting IOException");
        } catch (IOException e) {
            assertThat(e.getMessage(), is("boom"));
        }
        assertThat(handler.logRecords,
                contains(
                        allOf(hasProperty("message", is("[{0}] Initializing")),
                                hasProperty("parameters", is(new Object[] { "initSeq" }))),
                        allOf(hasProperty("message", is("[{0}] Starting")),
                                hasProperty("parameters", is(new Object[] { "initSeq" }))),
                        allOf(hasProperty("message", is("[{0}] Start failure")),
                                hasProperty("parameters", is(new Object[] { "initSeq" })),
                                hasProperty("thrown", hasProperty("message", is("boom"))))));
        assertThat("Init in sequence", state.get(), is(4));
    } finally {
        logger.removeHandler(handler);
        logger.setLevel(oldLevel);
    }
}

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 www  . j  a  v a 2  s . co 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: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);/*from ww  w. j av a  2 s.co m*/

    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(
            "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.wor.drawca.DrawCAMain.java

/**
 * Main function which start drawing the cellular automata.
 *
 * @param args Command line arguments.//from   w  w  w  .j a  v  a2  s .  c  o m
 */
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:ste.xtest.net.StubURLConnection.java

/**
 * Returns the resource output stream./*w w w.j a  v  a  2 s. c om*/
 * 
 * @return the connection output stream
 */
@Override
public OutputStream getOutputStream() throws IOException {
    if (out == null) {
        //
        // create the output stream
        //
        Logger LOG = Logger.getLogger("ste.xtest.net");

        Level level = LOG.getLevel();
        out = new LoggingByteArrayOutputStream(LOG, (level == null) ? Level.INFO : level, 2500);
    }

    return out;
}