Example usage for java.util.logging Handler flush

List of usage examples for java.util.logging Handler flush

Introduction

In this page you can find the example usage for java.util.logging Handler flush.

Prototype

public abstract void flush();

Source Link

Document

Flush any buffered output.

Usage

From source file:com.versusoft.packages.ooo.odt2daisy.gui.CommandLineGUI.java

public static void main(String args[]) throws IOException {

    Handler fh = new FileHandler(LOG_FILENAME_PATTERN);
    fh.setFormatter(new SimpleFormatter());

    //removeAllLoggersHandlers(Logger.getLogger(""));

    Logger.getLogger("").addHandler(fh);
    Logger.getLogger("").setLevel(Level.FINEST);

    Options options = new Options();

    Option option1 = new Option("in", "name of ODT file (required)");
    option1.setRequired(true);/*from   w  w  w.j  av a2 s  .c  o  m*/
    option1.setArgs(1);

    Option option2 = new Option("out", "name of DAISY DTB file (required)");
    option2.setRequired(true);
    option2.setArgs(1);

    Option option3 = new Option("h", "show this help");
    option3.setArgs(Option.UNLIMITED_VALUES);

    Option option4 = new Option("alt", "use alternate Level Markup");

    Option option5 = new Option("u", "UID of DAISY DTB (optional)");
    option5.setArgs(1);

    Option option6 = new Option("t", "Title of DAISY DTB");
    option6.setArgs(1);

    Option option7 = new Option("c", "Creator of DAISY DTB");
    option7.setArgs(1);

    Option option8 = new Option("p", "Publisher of DAISY DTB");
    option8.setArgs(1);

    Option option9 = new Option("pr", "Producer of DAISY DTB");
    option9.setArgs(1);

    Option option10 = new Option("pic", "set Picture directory");
    option10.setArgs(1);

    Option option11 = new Option("page", "enable pagination");
    option11.setArgs(0);

    Option option12 = new Option("css", "write CSS file");
    option12.setArgs(0);

    options.addOption(option1);
    options.addOption(option2);
    options.addOption(option3);
    options.addOption(option4);
    options.addOption(option5);
    options.addOption(option6);
    options.addOption(option7);
    options.addOption(option8);
    options.addOption(option9);
    options.addOption(option10);
    options.addOption(option11);
    options.addOption(option12);

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = null;

    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        //System.out.println("***ERROR: " + e.getClass() + ": " + e.getMessage());

        printHelp();
        return;
    }

    if (cmd.hasOption("help")) {
        printHelp();
        return;
    }

    try {

        Odt2Daisy odt2daisy = new Odt2Daisy(cmd.getOptionValue("in")); //@todo add initial output directory URL?
        odt2daisy.init();

        if (odt2daisy.isEmptyDocument()) {
            logger.info("Cannot convert empty documents. Export Aborted...");
            System.exit(1);
        }

        //System.out.println("Metadatas");
        //System.out.println("- title: " + odt2daisy.getTitleMeta());
        //System.out.println("- creator: " + odt2daisy.getCreatorMeta());

        if (!odt2daisy.isUsingHeadings()) {
            logger.info("You SHOULD use Heading styles in your document. Export in a single level.");
        }
        //@todo Warning for incompatible image formats should go here. See UnoGui.java.

        if (cmd.hasOption("u")) {
            //System.out.println("arg uid:"+cmd.getOptionValue("u"));
            odt2daisy.setUidParam(cmd.getOptionValue("u"));
        }

        if (cmd.hasOption("t")) {
            //System.out.println("arg title:"+cmd.getOptionValue("t"));
            odt2daisy.setTitleParam(cmd.getOptionValue("t"));
        }

        if (cmd.hasOption("c")) {
            //System.out.println("arg creator:"+cmd.getOptionValue("c"));
            odt2daisy.setCreatorParam(cmd.getOptionValue("c"));
        }

        if (cmd.hasOption("p")) {
            //System.out.println("arg publisher:"+cmd.getOptionValue("p"));
            odt2daisy.setPublisherParam(cmd.getOptionValue("p"));
        }

        if (cmd.hasOption("pr")) {
            //System.out.println("arg producer:"+cmd.getOptionValue("pr"));
            odt2daisy.setProducerParam(cmd.getOptionValue("pr"));
        }

        if (cmd.hasOption("alt")) {
            //System.out.println("arg alt:"+cmd.getOptionValue("alt"));
            odt2daisy.setUseAlternateLevelParam(true);
        }

        if (cmd.hasOption("css")) {
            odt2daisy.setWriteCSSParam(true);
        }

        if (cmd.hasOption("page")) {
            odt2daisy.paginationProcessing();
        }

        odt2daisy.correctionProcessing();

        if (cmd.hasOption("pic")) {

            odt2daisy.convertAsDTBook(cmd.getOptionValue("out"), cmd.getOptionValue("pic"));

        } else {

            logger.info("Language detected: " + odt2daisy.getLangParam());
            odt2daisy.convertAsDTBook(cmd.getOptionValue("out"), Configuration.DEFAULT_IMAGE_DIR);
        }

        boolean valid = odt2daisy.validateDTD(cmd.getOptionValue("out"));

        if (valid) {

            logger.info("DAISY DTBook produced is valid against DTD - Congratulations !");

        } else {

            logger.info("DAISY Book produced isn't valid against DTD - You SHOULD NOT use this DAISY Book !");
            logger.info("Error at line: " + odt2daisy.getErrorHandler().getLineNumber());
            logger.info("Error Message: " + odt2daisy.getErrorHandler().getMessage());
        }

    } catch (Exception e) {

        e.printStackTrace();

    } finally {

        if (fh != null) {
            fh.flush();
            fh.close();
        }
    }

}

From source file:com.versusoft.packages.ooo.odt2daisy.addon.gui.UnoGUI.java

/**
 * Flush any buffered output for the logger.
 *
 * @param fh The Handler object takes log messages from the Logger and exports them.
 *//*from ww  w  . j av a 2 s.  c o  m*/
private static void flushLogger(Handler fh) {
    if (fh != null) {
        fh.flush();
        fh.close();
    }
}

From source file:com.l2jfree.L2Config.java

/** Flushes all pending log entries. */
// FIXME MMOLogger.flush()
public static void flush() {
    // those are redirected to loggers, so flush them first
    System.out.flush();//w w  w.  j  a  va 2  s . c  o m
    System.err.flush();

    // then flush the loggers themselves
    final LogManager logManager = LogManager.getLogManager();

    for (String loggerName : Collections.list(logManager.getLoggerNames())) {
        if (loggerName == null)
            continue;

        final Logger logger = logManager.getLogger(loggerName);

        if (logger == null)
            continue;

        for (Handler handler : logger.getHandlers())
            if (handler != null)
                handler.flush();
    }

    // and finally the real console streams
    L2Config.out.flush();
    L2Config.err.flush();
}

From source file:com.google.appengine.tck.logservice.LoggingTestBase.java

protected void flush(Logger log) {
    ApiProxy.flushLogs();//from  w ww .  ja  va  2  s . c o  m
    for (Handler handler : log.getHandlers()) {
        handler.flush();
    }
}

From source file:com.skelril.aurora.jail.CSVInmateDatabase.java

public boolean unload() {

    for (Handler handler : auditLogger.getHandlers()) {
        if (handler instanceof FileHandler) {
            handler.flush();
            handler.close();//ww  w . ja  v  a2  s. c o  m
            auditLogger.removeHandler(handler);
            return true;
        }
    }
    return false;
}

From source file:com.skelril.aurora.jail.CSVJailCellDatabase.java

@Override
public boolean unload() {

    for (Handler handler : auditLogger.getHandlers()) {
        if (handler instanceof FileHandler) {
            handler.flush();
            handler.close();/*w  w  w . j a  v a 2  s .com*/
            auditLogger.removeHandler(handler);
            return true;
        }
    }
    return false;
}

From source file:org.apache.oodt.cas.pge.TestPGETaskInstance.java

@Test
@SuppressWarnings("unchecked") // FileUtils.readLines cast to List<String>
public void testLogger() throws Exception {
    PGETaskInstance pgeTask1 = createTestInstance();
    PGETaskInstance pgeTask2 = createTestInstance();

    pgeTask1.logger.log(Level.INFO, "pge1 message1");
    pgeTask1.logger.log(Level.INFO, "pge1 message2");
    pgeTask2.logger.log(Level.SEVERE, "pge2 message1");
    pgeTask1.logger.log(Level.INFO, "pge1 message3");

    for (Handler handler : pgeTask1.logger.getHandlers()) {
        handler.flush();
    }//from w w w .  j  av a2s.  c  o  m
    for (Handler handler : pgeTask2.logger.getHandlers()) {
        handler.flush();
    }
    File logDir = new File(pgeTask1.pgeConfig.getExeDir() + "/logs");
    assertTrue(logDir.exists());
    List<String> messages = FileUtils.readLines(logDir.listFiles(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.getName().endsWith(".log");
        }
    })[0], "UTF-8");
    assertEquals(Level.INFO.getLocalizedName() + ": pge1 message1", messages.get(1));
    assertEquals(Level.INFO.getLocalizedName() + ": pge1 message2", messages.get(3));
    assertEquals(Level.INFO.getLocalizedName() + ": pge1 message3", messages.get(5));
    logDir = new File(pgeTask2.pgeConfig.getExeDir() + "/logs");
    assertTrue(logDir.exists());
    messages = FileUtils.readLines(logDir.listFiles(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.getName().endsWith(".log");
        }
    })[0], "UTF-8");
    assertEquals(Level.SEVERE.getLocalizedName() + ": pge2 message1", messages.get(1));
}