List of usage examples for java.util.logging Handler setFormatter
public synchronized void setFormatter(Formatter newFormatter) throws SecurityException
From source file:BSxSB.Controllers.AdminController.java
@RequestMapping(value = "/editschool", method = RequestMethod.POST) public String editSchool(Model model, @RequestParam(value = "schoolID") String schoolID, @RequestParam(value = "schoolname") String schoolName, @RequestParam(value = "academicyear") String academicYear, @RequestParam(value = "numsemesters") String numSemesters, @RequestParam(value = "numdays") String numDays, @RequestParam(value = "numperiods") String numPeriods, @RequestParam(value = "lunchrange") String lunchRange) { try {//from w w w. ja va 2 s . c o m //Initialize the file that the logger writes to. Handler handler = new FileHandler("%tBSxSBAdminSchools.log", true); handler.setFormatter(new SimpleFormatter()); logger.addHandler(handler); logger.info("Admin Viewing List of School's Schedule Blocks."); boolean valid = true; if (schoolName.isEmpty() || academicYear.isEmpty() || numSemesters.isEmpty() || numPeriods.isEmpty() || lunchRange.isEmpty()) { model.addAttribute("fillout", "Please fill out all Required Fields"); valid = false; } int schoolid2 = Integer.parseInt(schoolID); String academicYearRegex = "[0-9]{4}-[0-9]{4}"; String lunchRangeRegex = "[0-9]-[0-9]"; int periods = Integer.parseInt(numPeriods); int days = Integer.parseInt(numDays); int semesters = Integer.parseInt(numSemesters); /* String legalBlockRegex = "(<[1-" + periods + "];([1-" + days + "](,[1-" + days + "]){0," + days + "})>)" + "(#<[1-" + periods + "];([1-" + days + "](,[1-" + days + "]){0," + days + "})>)*"; */ if (!academicYear.matches(academicYearRegex)) { model.addAttribute("ayregex", "Academic Year is invalid."); logger.info("Error: invalid academic year."); valid = false; } if (!lunchRange.matches(lunchRangeRegex)) { model.addAttribute("lrregex", "Lunch Range is invalid."); logger.info("Error: invalid lunch range."); valid = false; } if (valid == true) { SchoolDAO.editSchool(schoolid2, schoolName, academicYear, semesters, days, periods, lunchRange); //Check if scheduleblock string changed. If it didn't, then do NOT delete //Delete all existing scheduleblocks model.addAttribute("added", "School has been successfully edited."); logger.info("School was successfully edited"); } logger.removeHandler(handler); } catch (IOException ex) { logger.log(Level.SEVERE, null, ex); } catch (SecurityException ex) { logger.log(Level.SEVERE, null, ex); } return editRequest(model, schoolID); }
From source file:BSxSB.Controllers.AdminController.java
@RequestMapping(value = "/rejectaccount", method = RequestMethod.POST) public String rejectAccount(Model model, @RequestParam(value = "email") String email) { try {//from w ww . ja v a 2 s . c om //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> accountrequests = StudentDAO.getAccountRequests(); model.addAttribute("accountrequests", accountrequests); logger.info("Successfully rejected: " + 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 "adminmanagerequests"; }
From source file:BSxSB.Controllers.AdminController.java
@RequestMapping(value = "/acceptallaccount", method = RequestMethod.POST) public String acceptAllAccount(Model model) { try {/*from w w w. j a v a2 s . c o m*/ //Initialize the file that the logger writes to. Handler handler = new FileHandler("%tBSxSBAdminStudentAccts.log"); logger.addHandler(handler); handler.setFormatter(new SimpleFormatter()); StudentDAO.acceptAllAccount(); List<Students> accountrequests = StudentDAO.getAccountRequests(); model.addAttribute("accountrequests", accountrequests); logger.info("Successfully accepted all accounts"); 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 "adminmanagerequests"; }
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 www . j av a 2 s .c o 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"; }
From source file:BSxSB.Controllers.AdminController.java
@RequestMapping(value = "/acceptaccount", method = RequestMethod.POST) public String acceptAccount(Model model, @RequestParam(value = "email") String email) { try {/*from w ww .j a va2 s .c o m*/ //Initialize the file that the logger writes to. Handler handler = new FileHandler("%tBSxSBAdminStudentAccts.log"); logger.addHandler(handler); handler.setFormatter(new SimpleFormatter()); StudentDAO.acceptAccount(email); Students student = StudentDAO.getStudent(email); EmailNotification.sendEmail(student.getEmail(), student.getFirstname()); List<Students> accountrequests = StudentDAO.getAccountRequests(); model.addAttribute("accountrequests", accountrequests); logger.info("Successfully accepted: " + email); logger.info("Account 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 "adminmanagerequests"; }
From source file:BSxSB.Controllers.AdminController.java
@RequestMapping(value = "/addschool", method = RequestMethod.POST) public String addSchool(Model model, @RequestParam(value = "schoolname") String schoolName, @RequestParam(value = "academicyear") String academicYear, @RequestParam(value = "numsemesters") String numSemesters, @RequestParam(value = "numperiods") String numPeriods, @RequestParam(value = "numdays") String numDays, @RequestParam(value = "legalblocks") String legalBlocks, @RequestParam(value = "lunchrange") String lunchRange) { try {/*from ww w .j ava2 s. c o m*/ //Initialize the file that the logger writes to. Handler handler = new FileHandler("%tBSxSBAddSchool.log", true); handler.setFormatter(new SimpleFormatter()); logger.addHandler(handler); boolean valid = true; if (schoolName.isEmpty() || academicYear.isEmpty() || numSemesters.isEmpty() || numPeriods.isEmpty() || legalBlocks.isEmpty() || lunchRange.isEmpty()) { model.addAttribute("fillout", "Please fill out all Required Fields"); valid = false; } Schools school = SchoolDAO.getSchoolByNameYear(schoolName, academicYear); String academicYearRegex = "[0-9]{4}-[0-9]{4}"; String lunchRangeRegex = "[0-9]-[0-9]"; int periods = Integer.parseInt(numPeriods); int days = Integer.parseInt(numDays); int semesters = Integer.parseInt(numSemesters); String legalBlockRegex = "(<[1-" + periods + "];([1-" + days + "](,[1-" + days + "]){0," + days + "})>)" + "(#<[1-" + periods + "];([1-" + days + "](,[1-" + days + "]){0," + days + "})>)*"; if (!academicYear.matches(academicYearRegex)) { model.addAttribute("ayregex", "Academic Year is invalid"); logger.info("Invalid Academic Year"); valid = false; } if (!lunchRange.matches(lunchRangeRegex)) { model.addAttribute("lrregex", "Lunch Range is invalid"); logger.info("Invalid Lunch Range"); valid = false; } if (periods <= 9) { if (!legalBlocks.matches(legalBlockRegex)) { model.addAttribute("lbregex", "Legal Block set is invalid"); logger.info("Invalid Legal Block"); valid = false; } } if (school != null) { model.addAttribute("taken", "There is already a school with this name and academic year."); logger.info("Invalid name and academic year"); valid = false; } if (valid == true) { SchoolDAO.addSchool(schoolName, academicYear, semesters, days, periods, lunchRange); Schools tempSchool = SchoolDAO.getSchoolByNameYear(schoolName, academicYear); int schoolIDForSB = tempSchool.getSchoolid(); //Add all scheduleblocks String[] lbArray = legalBlocks.split("#"); //Array of strings in the format ({1;1,2,3} for (String s : lbArray) { String temp = s.substring(1, s.length() - 1); String[] tempArray = temp.split(";"); int pd = Integer.parseInt(tempArray[0]); ScheduleBlockDAO.addScheduleBlock(schoolIDForSB, pd, tempArray[1]); } model.addAttribute("added", "School has been successfully added."); logger.info("Successfully added school " + schoolName); } handler.close(); logger.removeHandler(handler); // Scheduleblocks are in the form of <period;day1,day2..>#<period;day1,day2..>. } catch (IOException ex) { logger.log(Level.SEVERE, null, ex); } catch (SecurityException ex) { logger.log(Level.SEVERE, null, ex); } return "adminaddschool"; }
From source file:com.comphenix.protocol.PacketLogging.java
private void startLogging() { manager.removePacketListener(this); if (sendingTypes.isEmpty() && receivingTypes.isEmpty()) { return;//from ww w . jav a 2s. c o m } this.sendingWhitelist = ListeningWhitelist.newBuilder().types(sendingTypes).build(); this.receivingWhitelist = ListeningWhitelist.newBuilder().types(receivingTypes).build(); // Setup the file logger if it hasn't been already if (location == LogLocation.FILE && fileLogger == null) { fileLogger = Logger.getLogger("ProtocolLib-FileLogging"); for (Handler handler : fileLogger.getHandlers()) fileLogger.removeHandler(handler); fileLogger.setUseParentHandlers(false); try { File logFile = new File(plugin.getDataFolder(), "log.log"); FileHandler handler = new FileHandler(logFile.getAbsolutePath(), true); handler.setFormatter(new LogFormatter()); fileLogger.addHandler(handler); } catch (IOException ex) { plugin.getLogger().log(Level.SEVERE, "Failed to obtain log file:", ex); return; } } manager.addPacketListener(this); }
From source file:org.syncany.cli.CommandLineClient.java
private void initLogHandlers(OptionSet options, OptionSpec<String> optionLog, OptionSpec<Void> optionLogPrint, OptionSpec<Void> optionDebug) throws SecurityException, IOException { // --log=<file> String logFilePattern = null; if (options.has(optionLog)) { if (!"-".equals(options.valueOf(optionLog))) { logFilePattern = options.valueOf(optionLog); }//w ww.j a va2s . com } else if (config != null && config.getLogDir().exists()) { logFilePattern = config.getLogDir() + File.separator + LOG_FILE_PATTERN; } else { logFilePattern = UserConfig.getUserLogDir() + File.separator + LOG_FILE_PATTERN; } if (logFilePattern != null) { Handler fileLogHandler = new FileHandler(logFilePattern, LOG_FILE_LIMIT, LOG_FILE_COUNT, true); fileLogHandler.setFormatter(new LogFormatter()); Logging.addGlobalHandler(fileLogHandler); } // --debug, add console handler if (options.has(optionDebug) || options.has(optionLogPrint) || (options.has(optionLog) && "-".equals(options.valueOf(optionLog)))) { Handler consoleLogHandler = new ConsoleHandler(); consoleLogHandler.setFormatter(new LogFormatter()); Logging.addGlobalHandler(consoleLogHandler); } }
From source file:org.openqa.selenium.server.mock.MockPIFrameUnitTest.java
private LoggingOptions configureLogging() throws Exception { // SeleniumServer.setDebugMode(true); LoggingOptions configuration = new LoggingOptions(); File target = new File("target"); if (target.exists() && target.isDirectory()) { configuration.setLogOutFile(new File(target, "mockpiframe.log")); } else {//w w w . j a v a2 s . com configuration.setLogOutFile(new File("mockpiframe.log")); } LoggingManager.configureLogging(configuration, false); Logger logger = Logger.getLogger(""); for (Handler handler : logger.getHandlers()) { if (handler instanceof StdOutHandler) { handler.setFormatter(new TerseFormatter(true)); break; } } return configuration; }
From source file:brut.apktool.Main.java
private static void setupLogging(Verbosity verbosity) { Logger logger = Logger.getLogger(""); for (Handler handler : logger.getHandlers()) { logger.removeHandler(handler);/* w ww . java 2 s . co m*/ } LogManager.getLogManager().reset(); if (verbosity == Verbosity.QUIET) { return; } Handler handler = new Handler() { @Override public void publish(LogRecord record) { if (getFormatter() == null) { setFormatter(new SimpleFormatter()); } try { String message = getFormatter().format(record); if (record.getLevel().intValue() >= Level.WARNING.intValue()) { System.err.write(message.getBytes()); } else { System.out.write(message.getBytes()); } } catch (Exception exception) { reportError(null, exception, ErrorManager.FORMAT_FAILURE); } } @Override public void close() throws SecurityException { } @Override public void flush() { } }; logger.addHandler(handler); if (verbosity == Verbosity.VERBOSE) { handler.setLevel(Level.ALL); logger.setLevel(Level.ALL); } else { handler.setFormatter(new Formatter() { @Override public String format(LogRecord record) { return record.getLevel().toString().charAt(0) + ": " + record.getMessage() + System.getProperty("line.separator"); } }); } }