List of usage examples for java.util.logging SimpleFormatter SimpleFormatter
SimpleFormatter
From source file:uk.sipperfly.ui.Exactly.java
/** * Initialize the logger./*from w w w.ja v a2s . co m*/ * Creates a log called "logfile.txt" in the current directory. */ public void initLogger() { logger = Logger.getLogger(GACOM); logger.setLevel(Level.INFO); try { filehandler = new FileHandler("logfile.txt"); simpleformatter = new SimpleFormatter(); filehandler.setFormatter(simpleformatter); } catch (IOException ex) { System.out.println(ex.getMessage()); } logger.addHandler(filehandler); }
From source file:com.piusvelte.taplock.server.TapLockServer.java
private static void initialize() { (new File(APP_PATH)).mkdir(); if (OS == OS_WIN) Security.addProvider(new BouncyCastleProvider()); System.out.println("APP_PATH: " + APP_PATH); try {/*from w ww . j a va 2 s . co m*/ sLogFileHandler = new FileHandler(sLog); } catch (SecurityException e) { writeLog("sLogFileHandler init: " + e.getMessage()); } catch (IOException e) { writeLog("sLogFileHandler init: " + e.getMessage()); } File propertiesFile = new File(sProperties); if (!propertiesFile.exists()) { try { propertiesFile.createNewFile(); } catch (IOException e) { writeLog("propertiesFile.createNewFile: " + e.getMessage()); } } Properties prop = new Properties(); try { prop.load(new FileInputStream(sProperties)); if (prop.isEmpty()) { prop.setProperty(sPassphraseKey, sPassphrase); prop.setProperty(sDisplaySystemTrayKey, Boolean.toString(sDisplaySystemTray)); prop.setProperty(sDebuggingKey, Boolean.toString(sDebugging)); prop.store(new FileOutputStream(sProperties), null); } else { if (prop.containsKey(sPassphraseKey)) sPassphrase = prop.getProperty(sPassphraseKey); else prop.setProperty(sPassphraseKey, sPassphrase); if (prop.containsKey(sDisplaySystemTrayKey)) sDisplaySystemTray = Boolean.parseBoolean(prop.getProperty(sDisplaySystemTrayKey)); else prop.setProperty(sDisplaySystemTrayKey, Boolean.toString(sDisplaySystemTray)); if (prop.containsKey(sDebuggingKey)) sDebugging = Boolean.parseBoolean(prop.getProperty(sDebuggingKey)); else prop.setProperty(sDebuggingKey, Boolean.toString(sDebugging)); } } catch (FileNotFoundException e) { writeLog("prop load: " + e.getMessage()); } catch (IOException e) { writeLog("prop load: " + e.getMessage()); } if (sLogFileHandler != null) { sLogger = Logger.getLogger("TapLock"); sLogger.setUseParentHandlers(false); sLogger.addHandler(sLogFileHandler); SimpleFormatter sf = new SimpleFormatter(); sLogFileHandler.setFormatter(sf); writeLog("service starting"); } if (sDisplaySystemTray && SystemTray.isSupported()) { final SystemTray systemTray = SystemTray.getSystemTray(); Image trayIconImg = Toolkit.getDefaultToolkit() .getImage(TapLockServer.class.getResource("/systemtrayicon.png")); final TrayIcon trayIcon = new TrayIcon(trayIconImg, "Tap Lock"); trayIcon.setImageAutoSize(true); PopupMenu popupMenu = new PopupMenu(); MenuItem aboutItem = new MenuItem("About"); CheckboxMenuItem toggleSystemTrayIcon = new CheckboxMenuItem("Display Icon in System Tray"); toggleSystemTrayIcon.setState(sDisplaySystemTray); CheckboxMenuItem toggleDebugging = new CheckboxMenuItem("Debugging"); toggleDebugging.setState(sDebugging); MenuItem shutdownItem = new MenuItem("Shutdown Tap Lock Server"); popupMenu.add(aboutItem); popupMenu.add(toggleSystemTrayIcon); if (OS == OS_WIN) { MenuItem setPasswordItem = new MenuItem("Set password"); popupMenu.add(setPasswordItem); setPasswordItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JPanel panel = new JPanel(); JLabel label = new JLabel("Enter your Windows account password:"); JPasswordField passField = new JPasswordField(32); panel.add(label); panel.add(passField); String[] options = new String[] { "OK", "Cancel" }; int option = JOptionPane.showOptionDialog(null, panel, "Tap Lock", JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); if (option == 0) { String password = encryptString(new String(passField.getPassword())); if (password != null) { Properties prop = new Properties(); try { prop.load(new FileInputStream(sProperties)); prop.setProperty(sPasswordKey, password); prop.store(new FileOutputStream(sProperties), null); } catch (FileNotFoundException e1) { writeLog("prop load: " + e1.getMessage()); } catch (IOException e1) { writeLog("prop load: " + e1.getMessage()); } } } } }); } popupMenu.add(toggleDebugging); popupMenu.add(shutdownItem); trayIcon.setPopupMenu(popupMenu); try { systemTray.add(trayIcon); } catch (AWTException e) { writeLog("systemTray.add: " + e.getMessage()); } aboutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String newline = System.getProperty("line.separator"); newline += newline; JOptionPane.showMessageDialog(null, "Tap Lock" + newline + "Copyright (c) 2012 Bryan Emmanuel" + newline + "This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version." + newline + "This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details." + newline + "You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>." + newline + "Bryan Emmanuel piusvelte@gmail.com"); } }); toggleSystemTrayIcon.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { setTrayIconDisplay(e.getStateChange() == ItemEvent.SELECTED); if (!sDisplaySystemTray) systemTray.remove(trayIcon); } }); toggleDebugging.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { setDebugging(e.getStateChange() == ItemEvent.SELECTED); } }); shutdownItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { shutdown(); } }); } synchronized (sConnectionThreadLock) { (sConnectionThread = new ConnectionThread()).start(); } }
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 .j a 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:de.phillme.PhotoSorter.java
private void initLogging() { System.setProperty("java.util.logging.SimpleFormatter.format", "%5$s %n"); LOGGER.setLevel(Level.INFO);/* w ww . j av a 2s . c om*/ ConsoleHandler handler = new ConsoleHandler(); handler.setFormatter(new SimpleFormatter()); handler.setLevel(Level.INFO); LOGGER.addHandler(handler); LOGGER.setUseParentHandlers(false); }
From source file:hudson.plugins.active_directory.docker.TheFlintstonesTest.java
private List<String> captureLogMessages(int size) { final List<String> logMessages = new ArrayList<>(size); Logger logger = Logger.getLogger(""); logger.setLevel(Level.ALL);/*from ww w. j a va2s . c o m*/ RingBufferLogHandler ringHandler = new RingBufferLogHandler(size) { final Formatter f = new SimpleFormatter(); // placeholder instance for what should have been a static method perhaps @Override public synchronized void publish(LogRecord record) { super.publish(record); String message = f.formatMessage(record); Throwable x = record.getThrown(); logMessages.add(message == null && x != null ? x.toString() : message); } }; logger.addHandler(ringHandler); return logMessages; }
From source file:com.yahoo.dba.perf.myperf.common.MyPerfContext.java
private void configureLogging() { Logger logger = Logger.getLogger(""); try {//w ww.jav a2 s .c o m logger.setLevel(Level.parse(getLogLevel())); } catch (Exception ex) { logger.setLevel(Level.INFO); } try { for (Handler h : logger.getHandlers()) { if (h instanceof java.util.logging.ConsoleHandler) h.setLevel(Level.SEVERE); } String logRoot = System.getProperty("logPath", "."); java.util.logging.FileHandler fileHandler = new java.util.logging.FileHandler( logRoot + File.separatorChar + getLogPath(), this.logFileSize, this.logFileCount); fileHandler.setLevel(logger.getLevel()); fileHandler.setFormatter(new SimpleFormatter()); logger.addHandler(fileHandler); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.sustainalytics.crawlerfilter.PDFTitleGeneration.java
/** * Method to initiate logger/*from w w w . ja va2 s .c o m*/ * @param file is a File object. The log file will be placed in this file's folder */ public static void initiateLogger(File file) { FileHandler fileHandler; try { // This block configure the logger with handler and formatter fileHandler = new FileHandler(file.getParentFile().getAbsolutePath() + "/" + "log.txt", true); logger.addHandler(fileHandler); SimpleFormatter formatter = new SimpleFormatter(); fileHandler.setFormatter(formatter); } catch (SecurityException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:BSxSB.Controllers.StudentController.java
@RequestMapping(value = "/studentcourseofferings", method = RequestMethod.GET) public String courseOfferings(Model model, @RequestParam(value = "year") String year) { try {/* w w w . j a v a 2 s . c o m*/ //Initialize the file that the logger writes to. Handler handler = new FileHandler("%tBSxSBStudentCourseOfferings.log", true); handler.setFormatter(new SimpleFormatter()); logger.addHandler(handler); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String name = auth.getName(); Students currentStudent = StudentDAO.getStudent(name); int schoolid = currentStudent.getSchoolid(); Schools sc = SchoolDAO.getSchool(schoolid); String schoolName = sc.getSchoolname(); Schools schoolYear = SchoolDAO.getSchoolByNameYear(schoolName, year); int schoolYearID = schoolYear.getSchoolid(); List<Courses> courses = CourseDAO.getCourseOfferingForSchool(schoolYearID); Schools currentSchool = SchoolDAO.getSchool(currentStudent.getSchoolid()); List<Schools> schoolyears = SchoolDAO.getSchoolSameName(currentSchool.getSchoolname()); List<Scheduleblocks> scheduleblocks = new ArrayList<>(); for (Courses course : courses) { scheduleblocks.add(ScheduleBlockDAO.getScheduleBlock(course.getScheduleblockid())); logger.info("Retrieved course: " + course.getCourseidentifier()); } model.addAttribute("scheduleblocks", scheduleblocks); model.addAttribute("schoolyears", schoolyears); model.addAttribute("courses", courses); handler.close(); logger.removeHandler(handler); } catch (IOException ex) { logger.log(Level.SEVERE, null, ex); } catch (SecurityException ex) { logger.log(Level.SEVERE, null, ex); } return "studentcourseofferings"; }
From source file:cz.cas.lib.proarc.desa.SIP2DESATransporter.java
private Handler setupLogHandler(String fileName) { Handler handler;/*from ww w . j a v a2s.c o m*/ try { checkDirectory(logRoot); handler = new FileHandler(logRoot + System.getProperty("file.separator") + fileName + ".txt", 0, 1, true); handler.setFormatter(new SimpleFormatter()); } catch (IOException e) { throw new RuntimeException(e); } Logger.getLogger("").addHandler(handler); return handler; }
From source file:de.lazyzero.kkMulticopterFlashTool.KKMulticopterFlashTool.java
private void initLogger() { try {/*from w w w. ja v a2 s . c o m*/ logFile = new FileHandler(LOG_FILE.getAbsolutePath(), false); logFile.setFormatter(new SimpleFormatter()); logFile.setLevel(Level.INFO); logger.addHandler(logFile); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } logger.setLevel(Level.INFO); }