Example usage for java.util.logging Logger fine

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

Introduction

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

Prototype

public void fine(Supplier<String> msgSupplier) 

Source Link

Document

Log a FINE message, which is only to be constructed if the logging level is such that the message will actually be logged.

Usage

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 ww .  j av  a2  s.c o  m
 */
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.
 * /*from  ww 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.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.torproject.ernie.db.ArchiveReader.java

public ArchiveReader(RelayDescriptorParser rdp, String archivesDir, boolean keepImportHistory) {
    int parsedFiles = 0, ignoredFiles = 0;
    Logger logger = Logger.getLogger(ArchiveReader.class.getName());
    SortedSet<String> archivesImportHistory = new TreeSet<String>();
    File archivesImportHistoryFile = new File("stats/archives-import-history");
    if (keepImportHistory && archivesImportHistoryFile.exists()) {
        try {/* w  w  w.j  a va 2  s  .  c o m*/
            BufferedReader br = new BufferedReader(new FileReader(archivesImportHistoryFile));
            String line = null;
            while ((line = br.readLine()) != null) {
                archivesImportHistory.add(line);
            }
            br.close();
        } catch (IOException e) {
            logger.log(Level.WARNING, "Could not read in archives import " + "history file. Skipping.");
        }
    }
    if (new File(archivesDir).exists()) {
        logger.fine("Importing files in directory " + archivesDir + "/...");
        Stack<File> filesInInputDir = new Stack<File>();
        filesInInputDir.add(new File(archivesDir));
        List<File> problems = new ArrayList<File>();
        while (!filesInInputDir.isEmpty()) {
            File pop = filesInInputDir.pop();
            if (pop.isDirectory()) {
                for (File f : pop.listFiles()) {
                    filesInInputDir.add(f);
                }
            } else {
                if (rdp != null) {
                    try {
                        BufferedInputStream bis = null;
                        if (keepImportHistory && archivesImportHistory.contains(pop.getName())) {
                            ignoredFiles++;
                            continue;
                        } else if (pop.getName().endsWith(".tar.bz2")) {
                            logger.warning(
                                    "Cannot parse compressed tarball " + pop.getAbsolutePath() + ". Skipping.");
                            continue;
                        } else if (pop.getName().endsWith(".bz2")) {
                            FileInputStream fis = new FileInputStream(pop);
                            BZip2CompressorInputStream bcis = new BZip2CompressorInputStream(fis);
                            bis = new BufferedInputStream(bcis);
                        } else {
                            FileInputStream fis = new FileInputStream(pop);
                            bis = new BufferedInputStream(fis);
                        }
                        if (keepImportHistory) {
                            archivesImportHistory.add(pop.getName());
                        }
                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
                        int len;
                        byte[] data = new byte[1024];
                        while ((len = bis.read(data, 0, 1024)) >= 0) {
                            baos.write(data, 0, len);
                        }
                        bis.close();
                        byte[] allData = baos.toByteArray();
                        rdp.parse(allData);
                        parsedFiles++;
                    } catch (IOException e) {
                        problems.add(pop);
                        if (problems.size() > 3) {
                            break;
                        }
                    }
                }
            }
        }
        if (problems.isEmpty()) {
            logger.fine("Finished importing files in directory " + archivesDir + "/.");
        } else {
            StringBuilder sb = new StringBuilder(
                    "Failed importing files in " + "directory " + archivesDir + "/:");
            int printed = 0;
            for (File f : problems) {
                sb.append("\n  " + f.getAbsolutePath());
                if (++printed >= 3) {
                    sb.append("\n  ... more");
                    break;
                }
            }
        }
    }
    if (keepImportHistory) {
        try {
            archivesImportHistoryFile.getParentFile().mkdirs();
            BufferedWriter bw = new BufferedWriter(new FileWriter(archivesImportHistoryFile));
            for (String line : archivesImportHistory) {
                bw.write(line + "\n");
            }
            bw.close();
        } catch (IOException e) {
            logger.log(Level.WARNING, "Could not write archives import " + "history file.");
        }
    }
    logger.info("Finished importing relay descriptors from local " + "directory:\nParsed " + parsedFiles
            + ", ignored " + ignoredFiles + " files.");
}

From source file:org.torproject.ernie.db.BridgeSnapshotReader.java

public BridgeSnapshotReader(BridgeDescriptorParser bdp, String bridgeDirectoriesDir) {
    Logger logger = Logger.getLogger(BridgeSnapshotReader.class.getName());
    SortedSet<String> parsed = new TreeSet<String>();
    File bdDir = new File(bridgeDirectoriesDir);
    File pbdFile = new File("stats/parsed-bridge-directories");
    boolean modified = false;
    if (bdDir.exists()) {
        if (pbdFile.exists()) {
            logger.fine("Reading file " + pbdFile.getAbsolutePath() + "...");
            try {
                BufferedReader br = new BufferedReader(new FileReader(pbdFile));
                String line = null;
                while ((line = br.readLine()) != null) {
                    parsed.add(line);//from  w  w  w . j av a  2s .  c  o  m
                }
                br.close();
                logger.fine("Finished reading file " + pbdFile.getAbsolutePath() + ".");
            } catch (IOException e) {
                logger.log(Level.WARNING, "Failed reading file " + pbdFile.getAbsolutePath() + "!", e);
                return;
            }
        }
        logger.fine("Importing files in directory " + bridgeDirectoriesDir + "/...");
        Stack<File> filesInInputDir = new Stack<File>();
        filesInInputDir.add(bdDir);
        while (!filesInInputDir.isEmpty()) {
            File pop = filesInInputDir.pop();
            if (pop.isDirectory()) {
                for (File f : pop.listFiles()) {
                    filesInInputDir.add(f);
                }
            } else if (!parsed.contains(pop.getName())) {
                try {
                    FileInputStream in = new FileInputStream(pop);
                    if (in.available() > 0) {
                        GzipCompressorInputStream gcis = new GzipCompressorInputStream(in);
                        TarArchiveInputStream tais = new TarArchiveInputStream(gcis);
                        BufferedInputStream bis = new BufferedInputStream(tais);
                        String fn = pop.getName();
                        String dateTime = fn.substring(11, 21) + " " + fn.substring(22, 24) + ":"
                                + fn.substring(24, 26) + ":" + fn.substring(26, 28);
                        while ((tais.getNextTarEntry()) != null) {
                            ByteArrayOutputStream baos = new ByteArrayOutputStream();
                            int len;
                            byte[] data = new byte[1024];
                            while ((len = bis.read(data, 0, 1024)) >= 0) {
                                baos.write(data, 0, len);
                            }
                            byte[] allData = baos.toByteArray();
                            if (allData.length == 0) {
                                continue;
                            }
                            String ascii = new String(allData, "US-ASCII");
                            BufferedReader br3 = new BufferedReader(new StringReader(ascii));
                            String firstLine = null;
                            while ((firstLine = br3.readLine()) != null) {
                                if (firstLine.startsWith("@")) {
                                    continue;
                                } else {
                                    break;
                                }
                            }
                            if (firstLine.startsWith("r ")) {
                                bdp.parse(allData, dateTime, false);
                            } else {
                                int start = -1, sig = -1, end = -1;
                                String startToken = firstLine.startsWith("router ") ? "router " : "extra-info ";
                                String sigToken = "\nrouter-signature\n";
                                String endToken = "\n-----END SIGNATURE-----\n";
                                while (end < ascii.length()) {
                                    start = ascii.indexOf(startToken, end);
                                    if (start < 0) {
                                        break;
                                    }
                                    sig = ascii.indexOf(sigToken, start);
                                    if (sig < 0) {
                                        break;
                                    }
                                    sig += sigToken.length();
                                    end = ascii.indexOf(endToken, sig);
                                    if (end < 0) {
                                        break;
                                    }
                                    end += endToken.length();
                                    byte[] descBytes = new byte[end - start];
                                    System.arraycopy(allData, start, descBytes, 0, end - start);
                                    bdp.parse(descBytes, dateTime, false);
                                }
                            }
                        }
                    }
                    in.close();

                    /* Let's give some memory back, or we'll run out of it. */
                    System.gc();

                    parsed.add(pop.getName());
                    modified = true;
                } catch (IOException e) {
                    logger.log(Level.WARNING, "Could not parse bridge snapshot " + pop.getName() + "!", e);
                    continue;
                }
            }
        }
        logger.fine("Finished importing files in directory " + bridgeDirectoriesDir + "/.");
        if (!parsed.isEmpty() && modified) {
            logger.fine("Writing file " + pbdFile.getAbsolutePath() + "...");
            try {
                pbdFile.getParentFile().mkdirs();
                BufferedWriter bw = new BufferedWriter(new FileWriter(pbdFile));
                for (String f : parsed) {
                    bw.append(f + "\n");
                }
                bw.close();
                logger.fine("Finished writing file " + pbdFile.getAbsolutePath() + ".");
            } catch (IOException e) {
                logger.log(Level.WARNING, "Failed writing file " + pbdFile.getAbsolutePath() + "!", e);
            }
        }
    }
}

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));

}

From source file:org.usrz.libs.logging.LevelWarningTest.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.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));

}