List of usage examples for java.util.logging FileHandler FileHandler
public FileHandler(String pattern, boolean append) throws IOException, SecurityException
From source file:com.skelril.aurora.jail.CSVInmateDatabase.java
public CSVInmateDatabase(File inmateStorageDir) { inmateFile = new File(inmateStorageDir, "inmates.csv"); // Set up an audit trail try {/*from w ww . ja va 2 s . co m*/ FileHandler handler = new FileHandler( (new File(inmateStorageDir, "inmates.%g.%u.log")).getAbsolutePath().replace("\\", "/"), true); handler.setFormatter(new Formatter() { @Override public String format(LogRecord record) { return "[" + dateFormat.format(new Date()) + "] " + record.getMessage() + "\r\n"; } }); auditLogger.addHandler(handler); } catch (SecurityException | IOException e) { log.warning("Failed to setup audit log for the " + "CSV inmate database: " + e.getMessage()); } }
From source file:com.skelril.aurora.jail.CSVJailCellDatabase.java
public CSVJailCellDatabase(File cellStorageDir) { cellFile = new File(cellStorageDir, "cells.csv"); // Set up an audit trail try {/* www. j a v a2 s . c o m*/ FileHandler handler = new FileHandler( (new File(cellStorageDir, "cells.%g.%u.log")).getAbsolutePath().replace("\\", "/"), true); handler.setFormatter(new java.util.logging.Formatter() { @Override public String format(LogRecord record) { return "[" + dateFormat.format(new Date()) + "] " + record.getMessage() + "\r\n"; } }); auditLogger.addHandler(handler); } catch (SecurityException | IOException e) { log.warning("Failed to setup audit log for the CSV cell database: " + e.getMessage()); } }
From source file:uk.nhs.cfh.dsp.srth.distribution.FileDownloader.java
public FileDownloader(FTPClient ftpClient) { this.ftpClient = ftpClient; try {/*w ww . j a v a2s . c om*/ logger.addHandler( new FileHandler(System.getProperty("java.io.tmpdir") + SEPARATOR + "configurator.log", true)); } catch (IOException e) { logger.warning(ERR_MESSAGE + e.fillInStackTrace().getMessage()); } }
From source file:nl.minvenj.pef.stream.LiveCapture.java
/** * Initializes a logger.// w w w . j a va 2 s . c om * * @param logPath The location and name of the log file * @throws SecurityException on opening the log file * @throws IOException on opening the log file */ private static void initLogger(final String logPath) throws SecurityException, IOException, IllegalArgumentException { logFileHandler = new FileHandler(logPath, true); Logger initLogger = Logger.getLogger(""); logFileHandler.setFormatter(new SimpleFormatter()); initLogger.addHandler(logFileHandler); initLogger.setLevel(Level.CONFIG); }
From source file:fr.ippon.wip.util.WIPLogging.java
private WIPLogging() { try {// ww w . ja v a 2 s . c om // FileHandler launch an exception if parent path doesn't exist, so // we make sure it exists File logDirectory = new File(HOME + "/wip"); if (!logDirectory.exists() || !logDirectory.isDirectory()) logDirectory.mkdirs(); accessFileHandler = new FileHandler("%h/wip/access.log", true); accessFileHandler.setLevel(Level.INFO); accessFileHandler.setFormatter(new SimpleFormatter()); Logger.getLogger("fr.ippon.wip.http.hc.HttpClientExecutor.AccessLog").addHandler(accessFileHandler); ConsoleHandler consoleHandler = new ConsoleHandler(); consoleHandler.setFilter(new Filter() { public boolean isLoggable(LogRecord record) { return !record.getLoggerName().equals("fr.ippon.wip.http.hc.HttpClientExecutor.AccessLog"); } }); Logger.getLogger("fr.ippon.wip").addHandler(consoleHandler); // For HttpClient debugging // FileHandler fileHandler = new // FileHandler("%h/wip/httpclient.log", true); // fileHandler.setLevel(Level.ALL); // Logger.getLogger("org.apache.http.headers").addHandler(fileHandler); // Logger.getLogger("org.apache.http.headers").setLevel(Level.ALL); } catch (SecurityException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:prm4j.indexing.monitor.ParametricMonitorLogger.java
/** * A simple file logger which outputs only the message. * //from ww w. j a va2s. c o m * @param fileName * path to the output file * @return the logger */ private static Logger getFileLogger(String fileName) { // make sure parent directories exist new File(fileName).getParentFile().mkdirs(); final Logger logger = Logger.getLogger(fileName); try { logger.setUseParentHandlers(false); Handler handler = new FileHandler(fileName, true); handler.setFormatter(new Formatter() { @Override public String format(LogRecord record) { return record.getMessage() + "\n"; } }); logger.addHandler(handler); } catch (Exception e) { throw new RuntimeException(e); } return logger; }
From source file:com.nilostep.xlsql.database.xlInstance.java
private xlInstance(String cfg) throws xlException { logger = Logger.getLogger(this.getClass().getName()); instance = this; try {/* www. j ava 2 s . c o m*/ PropertiesConfiguration config = new PropertiesConfiguration(); config.load(this.getClass().getResourceAsStream(cfg + ".properties")); this.config = config; engine = config.getString("general.engine"); logger.info("Configuration engine: " + engine + " loaded"); } catch (ConfigurationException e) { e.printStackTrace(); throw new xlException(e.getMessage()); } try { boolean append = true; FileHandler loghandler = new FileHandler(getLog(), append); loghandler.setFormatter(new SimpleFormatter()); logger.addHandler(loghandler); } catch (IOException e) { throw new xlException("error while creating logfile"); } logger.info("Instance created with engine " + getEngine()); }
From source file:mop.MemoryLogger.java
/** * A simple file logger which outputs only the message. * * @param fileName//from ww w . j a va 2 s . c om * path to the output file * @return the logger */ private static Logger getFileLogger(String fileName) { final Logger logger = Logger.getLogger(fileName); try { logger.setUseParentHandlers(false); Handler handler = new FileHandler(fileName, true); handler.setFormatter(new Formatter() { @Override public String format(LogRecord record) { return record.getMessage() + "\n"; } }); logger.addHandler(handler); } catch (Exception e) { throw new RuntimeException(e); } return logger; }
From source file:BSxSB.Controllers.StudentController.java
@RequestMapping(value = "/register", method = RequestMethod.POST) public String register(Model model, @RequestParam(value = "firstName") String firstName, @RequestParam(value = "lastName") String lastName, @RequestParam(value = "email") String email, @RequestParam(value = "password") String password, @RequestParam(value = "school") String school) { try {/*from www. j a v a 2 s . c o m*/ //Initialize the file that the logger writes to. Handler handler = new FileHandler("%tBSxSBStudentAccount.log", true); handler.setFormatter(new SimpleFormatter()); logger.addHandler(handler); List<Schools> schools = SchoolDAO.allSchools(); if (schools != null) { model.addAttribute("school", schools); } Students student = StudentDAO.getStudent(email); if (firstName.isEmpty() || lastName.isEmpty() || email.isEmpty() || password.isEmpty()) { model.addAttribute("fillout", "Please fill out all Required Fields"); logger.info("A field was not filled."); } else if (student != null) { model.addAttribute("taken", "The email address is taken"); logger.info("Email address was taken."); } else { StudentDAO.register(firstName, lastName, email, password, school); model.addAttribute("registered", "You have been successfully registered. Please Login"); logger.info("Successfully registered an account with email " + email); } handler.close(); logger.removeHandler(handler); } catch (IOException ex) { logger.log(Level.SEVERE, null, ex); } catch (SecurityException ex) { logger.log(Level.SEVERE, null, ex); } return "index"; }
From source file:de.teamgrit.grit.entities.Controller.java
/** * Instantiates a new controller.//from w w w.ja v a 2s . co m */ private Controller() { m_courses = new HashMap<>(); m_connections = new HashMap<>(); try { // create log directory if it does not exist if (!Paths.get("log").toFile().exists()) { File logFolder = new File("log"); logFolder.mkdir(); } // Tell the logger to log there. FileHandler fh = new FileHandler(Paths.get("log", "system.log").toString(), true); LOGGER.addHandler(fh); // log in human readable format fh.setFormatter(new SimpleFormatter()); // do not log to console LOGGER.setUseParentHandlers(false); } catch (SecurityException | IOException e) { System.err.println("Could not start logger on log/system.log: " + e.getMessage()); e.printStackTrace(); } try { m_config = new Configuration(CONFIG_LOCATION.toFile()); } catch (ConfigurationException | FileNotFoundException e) { LOGGER.severe("Error while creating Controller: " + e.getMessage()); } }