Example usage for java.util.logging Logger isLoggable

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

Introduction

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

Prototype

public boolean isLoggable(Level level) 

Source Link

Document

Check if a message of the given level would actually be logged by this logger.

Usage

From source file:org.jdesktop.wonderland.modules.service.InstallManager.java

/**
 * Returns a map of module names and objects from a given directory. If no
 * modules are present, this method returns an empty map.
 * //from w  w  w  . j  a  v a 2  s  .c o m
 * @return An map of unique module names and their Module objects
 */
private Map<String, Module> fetchModules() {
    Logger logger = ModuleManager.getLogger();
    Map<String, Module> map = new HashMap<String, Module>();

    /*
     * Loop through each file and check that it is potentially valid.
     * If so, add its name to the map of module names
     */
    File[] files = this.installedFile.listFiles();
    for (File file : files) {
        /* Attempt to create the module */
        try {
            Module module = ModuleFactory.open(file);
            map.put(module.getName(), module);

            if (logger.isLoggable(Level.FINE)) {
                logger.fine("Load installed module " + module);
            }
        } catch (java.lang.Exception excp) {
            ModuleManager.getLogger().log(Level.WARNING, "[MODULES] Invalid module " + file, excp);
        }
    }
    return map;
}

From source file:org.jdesktop.wonderland.modules.service.PendingManager.java

/**
 * Adds a new module to be pending. Returns the new module object, or null
 * upon error./*from  w w  w.  j av  a2  s. c  om*/
 */
public Module add(File jarFile) {
    /* Get the error logger */
    Logger logger = ModuleManager.getLogger();

    /* First attempt to open the URL as a module */
    Module module = null;
    try {
        module = ModuleFactory.open(jarFile);
    } catch (java.lang.Exception excp) {
        /* Log the error and return false */
        logger.log(Level.WARNING, "[MODULES] PENDING Failed to Open Module " + jarFile, excp);
        return null;
    }

    /* Next, see the module already exists, log warning and continue */
    if (this.pendingModules.containsKey(module.getName()) == true) {
        logger.log(Level.INFO, "[MODULES] PENDING Module already exists " + module.getName());
    }

    /* Add to the pending/ directory */
    File file = this.addToPending(module.getName(), jarFile);
    if (file == null) {
        logger.log(Level.WARNING, "[MODULES] PENDING Failed to add " + module.getName());
        return null;
    }

    /* Re-open the module in the new directory */
    try {
        module = ModuleFactory.open(file);

        if (logger.isLoggable(Level.FINE)) {
            logger.fine("Add pending module " + module);
        }
    } catch (java.lang.Exception excp) {
        /* Log the error and return false */
        logger.log(Level.WARNING, "[MODULES] PENDING Failed to Open Module " + file, excp);
        return null;
    }
    /* If successful, add to the list of pending modules */
    this.pendingModules.put(module.getName(), module);
    return module;
}

From source file:org.jdesktop.wonderland.modules.service.PendingManager.java

/**
 * Returns a map of module names and objects from a given directory. If no
 * modules are present, this method returns an empty map.
 * //  w ww  .j ava2  s.  c o  m
 * @return An map of unique module names and their Module objects
 */
private Map<String, Module> fetchModules() {
    Logger logger = ModuleManager.getLogger();
    Map<String, Module> map = new HashMap<String, Module>();

    /*
     * Loop through each file and check that it is potentially valid.
     * If so, add its name to the map of module names
     */
    File[] files = this.pendingFile.listFiles();
    for (File file : files) {
        /* Attempt to create the module */
        try {
            Module module = ModuleFactory.open(file);
            map.put(module.getName(), module);

            if (logger.isLoggable(Level.FINE)) {
                logger.fine("Load pending module " + module);
            }
        } catch (java.lang.Exception excp) {
            ModuleManager.getLogger().log(Level.WARNING, "[MODULES] Invalid module " + file, excp);
        }
    }
    return map;
}

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);/* w  w  w.  jav  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
            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  ww w  . j a  va  2s.com*/
    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);//  ww w .  ja v a  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
            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.openconcerto.sql.model.SQLBase.java

static public final void logCacheError(final DBItemFileCache dir, Exception e) {
    final Logger logger = Log.get();
    if (logger.isLoggable(Level.CONFIG))
        logger.log(Level.CONFIG, "invalid files in " + dir, e);
    else//from   www.j a  va2 s .com
        logger.info("invalid files in " + dir + "\n" + e.getMessage());
}

From source file:org.protempa.backend.dsb.relationaldb.AbstractSQLGenerator.java

@Override
public final boolean loadDriverIfNeeded() {
    String className = getDriverClassNameToLoad();
    if (className == null) {
        return true;
    }/*ww  w.ja  va 2s .c o  m*/
    try {
        Class.forName(className);
        return true;
    } catch (ClassNotFoundException ex) {
        Logger logger = SQLGenUtil.logger();
        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE, "{0} when trying to load {1}.",
                    new Object[] { ex.getClass().getName(), className });
        }
        return false;
    }
}

From source file:org.protempa.backend.dsb.relationaldb.AbstractSQLGenerator.java

private void logDoneProcessing(Logger logger, EntitySpec entitySpec) {
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "Results of query for {0} in data source backend {1} " + "have been processed",
                new Object[] { entitySpec.getName(), backendNameForMessages() });
    }//from w  w w .  ja v a2  s .c  o m
}

From source file:org.protempa.backend.dsb.relationaldb.AbstractSQLGenerator.java

private void logProcessingEntitySpec(Logger logger, EntitySpec entitySpec) {
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "Data source backend {0} is processing entity spec {1}",
                new Object[] { backendNameForMessages(), entitySpec.getName() });
    }/*www  .j  av a  2 s  .  c o m*/
}