List of usage examples for java.util.logging Handler close
public abstract void close() throws SecurityException;
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);// www. j a va2 s . com 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:MailHandlerDemo.java
/** * Close and remove all handlers added to the class logger. *//*from ww w .jav a2 s . com*/ private static void closeHandlers() { Handler[] handlers = LOGGER.getHandlers(); for (Handler h : handlers) { h.close(); LOGGER.removeHandler(h); } }
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 www .j a v a 2s . c o m*/ private static void flushLogger(Handler fh) { if (fh != null) { fh.flush(); fh.close(); } }
From source file:cz.cas.lib.proarc.desa.SIP2DESATransporter.java
private static void removeLogHandler(Handler handler) { Logger.getLogger("").removeHandler(handler); handler.close(); }
From source file:com.skelril.aurora.jail.CSVInmateDatabase.java
public boolean unload() { for (Handler handler : auditLogger.getHandlers()) { if (handler instanceof FileHandler) { handler.flush();// w ww .j a v a 2 s . c om handler.close(); 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();/*w ww .ja v a 2 s . c om*/ handler.close(); auditLogger.removeHandler(handler); return true; } } return false; }
From source file:com.redhat.rcm.version.Cli.java
private static void configureLogging(boolean useConsole, final boolean useLogFile, final File logFile) { System.out.println("Log file is: " + logFile.getAbsolutePath()); final List<Handler> handlers = new ArrayList<Handler>(); if (!useConsole && !useLogFile) { if (!useLogFile) { System.out.println(/* w w w . j a va 2 s . c o m*/ "\n\nNOTE: --no-console option has been OVERRIDDEN since --no-log-file option was also provided.\nOutputting to console ONLY.\n"); useConsole = true; } } if (useConsole) { final Handler chandler = new ConsoleHandler(); chandler.setFormatter(new VManFormatter()); chandler.setLevel(Level.ALL); handlers.add(chandler); } if (useLogFile) { try { final File dir = logFile.getParentFile(); if (dir != null && !dir.isDirectory() && !dir.mkdirs()) { throw new RuntimeException( "Failed to create parent directory for logfile: " + dir.getAbsolutePath()); } final Handler fhandler = new FileHandler(logFile.getPath(), false); fhandler.setFormatter(new VManFormatter()); fhandler.setLevel(Level.ALL); handlers.add(fhandler); } catch (final IOException e) { final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); System.out.printf("ERROR: Failed to initialize log file: %s. Reason: %s\n\n%s\n\n", logFile, e.getMessage(), sw.toString()); throw new RuntimeException("Failed to initialize logfile."); } } root.setUseParentHandlers(false); final Handler[] currenthandlers = root.getHandlers(); for (final Handler h : currenthandlers) { h.close(); root.removeHandler(h); } for (final Handler h : handlers) { root.addHandler(h); } }
From source file:com.twitter.heron.instance.HeronInstance.java
public void stop() { synchronized (this) { LOG.severe("Instance Process exiting.\n"); for (Handler handler : java.util.logging.Logger.getLogger("").getHandlers()) { handler.close(); }//from w w w . j a va 2 s . c o m // Attempts to shutdown all the thread in threadsPool. This will send Interrupt to every // thread in the pool. Threads may implement a clean Interrupt logic. threadsPool.shutdownNow(); // TODO : It is not clear if this signal should be sent to all the threads (including threads // not owned by HeronInstance). To be safe, not sending these interrupts. Runtime.getRuntime().halt(1); } }
From source file:BSxSB.Controllers.AdminController.java
@RequestMapping(value = "/deletescheduleblock", method = RequestMethod.POST) public String deleteScheduleBlocks(Model model, @RequestParam(value = "scheduleblockID") String scheduleblockID, @RequestParam(value = "schoolid") String schoolid) { try {/*from w w w . java 2 s . co m*/ //Initialize the file that the logger writes to. Handler handler = new FileHandler("%tBSxSBAdminScheduleBlocks.log", true); handler.setFormatter(new SimpleFormatter()); logger.addHandler(handler); logger.info("Admin Viewing List of School's Schedule Blocks."); int sbid = Integer.parseInt(scheduleblockID); ScheduleBlockDAO.deleteScheduleBlock(sbid); logger.info("Scheduleblock " + sbid + " was deleted."); handler.close(); logger.removeHandler(handler); } catch (IOException ex) { logger.log(Level.SEVERE, null, ex); } catch (SecurityException ex) { logger.log(Level.SEVERE, null, ex); } return editScheduleBlocks(model, schoolid); }
From source file:BSxSB.Controllers.AdminController.java
@RequestMapping(value = "/deleteaccount", method = RequestMethod.POST) public String deleteAccount(Model model, @RequestParam(value = "email") String email) { try {/*from ww w. ja v a2 s . co m*/ //Initialize the file that the logger writes to. Handler handler = new FileHandler("%tBSxSBAdminStudentAccts.log"); logger.addHandler(handler); handler.setFormatter(new SimpleFormatter()); StudentDAO.deleteAccount(email); List<Students> allStudents = StudentDAO.getAcceptedAccounts(); model.addAttribute("allstudents", allStudents); logger.info("Successfully deleted: " + email); logger.info("Accounts successfully updated to model"); handler.close(); } catch (IOException ex) { logger.log(Level.SEVERE, null, ex); } catch (SecurityException ex) { logger.log(Level.SEVERE, null, ex); } return "adminmanageaccounts"; }