List of usage examples for java.util.logging FileHandler FileHandler
public FileHandler(String pattern) throws IOException, SecurityException
From source file:jshm.logging.Log.java
public static void reloadConfig() throws Exception { // all logging Handler consoleHandler = new ConsoleHandler(); consoleHandler.setLevel(DEBUG ? Level.ALL : Level.WARNING); consoleHandler.setFormatter(new OneLineFormatter()); Logger cur = Logger.getLogger(""); removeHandlers(cur);/*from w w w . j a va 2 s. c om*/ cur.addHandler(consoleHandler); // jshm logging Formatter fileFormatter = new FileFormatter(); Handler jshmHandler = new FileHandler("data/logs/JSHManager.txt"); jshmHandler.setLevel(Level.ALL); jshmHandler.setFormatter(fileFormatter); cur = Logger.getLogger("jshm"); cur.addHandler(jshmHandler); cur.setLevel(DEBUG ? Level.ALL : Level.INFO); // hibernate logging Handler hibernateHandler = new FileHandler("data/logs/Hibernate.txt"); hibernateHandler.setLevel(Level.ALL); hibernateHandler.setFormatter(fileFormatter); cur = Logger.getLogger("org.hibernate"); removeHandlers(cur); cur.addHandler(hibernateHandler); cur.setLevel(DEBUG ? Level.INFO : Level.WARNING); // HttpClient logging Handler httpClientHandler = new FileHandler("data/logs/HttpClient.txt"); httpClientHandler.setLevel(Level.ALL); httpClientHandler.setFormatter(fileFormatter); // cur = Logger.getLogger("httpclient.wire"); cur = Logger.getLogger("httpclient.wire.header"); removeHandlers(cur); cur.addHandler(httpClientHandler); cur.setLevel(DEBUG ? Level.ALL : Level.INFO); cur = Logger.getLogger("org.apache.commons.httpclient"); removeHandlers(cur); cur.addHandler(httpClientHandler); cur.setLevel(DEBUG ? Level.FINER : Level.INFO); // HtmlParser logging Handler htmlParserHandler = new FileHandler("data/logs/HtmlParser.txt"); htmlParserHandler.setLevel(Level.ALL); htmlParserHandler.setFormatter(fileFormatter); cur = Logger.getLogger("org.htmlparser"); removeHandlers(cur); cur.addHandler(htmlParserHandler); cur.setLevel(DEBUG ? Level.ALL : Level.INFO); // SwingX logging Handler swingxHandler = new FileHandler("data/logs/SwingX.txt"); swingxHandler.setLevel(Level.ALL); swingxHandler.setFormatter(fileFormatter); cur = Logger.getLogger("org.jdesktop.swingx"); removeHandlers(cur); cur.addHandler(swingxHandler); cur.setLevel(DEBUG ? Level.ALL : Level.INFO); }
From source file:com.ibm.ctg.samples.cloudmonitor.CloudMonitor.java
public CloudMonitor() throws SecurityException, IOException { log = Logger.getLogger(this.getClass().getCanonicalName()); String logName = System.getProperty(LOG_NAME_PROPERTY); if (logName != null && logName.length() > 0) { log.addHandler(new FileHandler(logName)); }/*from ww w . jav a2 s . c o m*/ DB_URL = System.getProperty(DB_URL_PROPERTY); Thread dbStore = new Thread(new DBStore()); dbStore.setDaemon(true); dbStore.start(); }
From source file:com.speed.ob.Obfuscator.java
public Obfuscator(final Config config) { transforms = new LinkedList<>(); store = new ClassStore(); this.config = config; //set up logging this.LOGGER = Logger.getLogger(this.getClass().getName()); LOGGER.info("Ob2 is starting"); String logLvl = config.get("Obfuscator.logging"); String logDir = config.get("Obfuscator.log_dir"); level = parseLevel(logLvl);//from w ww . jav a 2 s. co m LOGGER.info("Logger level set to " + level.getName()); Logger topLevel = Logger.getLogger(""); topLevel.setLevel(level); File logs = new File(logDir); if (!logs.exists()) { if (!logs.mkdir()) Logger.getLogger(this.getClass().getName()).warning("Could not create logging directory"); } try { if (logs.exists()) { fHandler = new FileHandler(logs.getAbsolutePath() + File.separator + "ob%g.log"); topLevel.addHandler(fHandler); } } catch (IOException e) { e.printStackTrace(); } for (Handler handler : topLevel.getHandlers()) { handler.setLevel(level); } //populate transforms LOGGER.info("Configuring Ob"); LOGGER.fine("Parsing config"); if (config.getBoolean("Obfuscator.all_transforms")) { LOGGER.fine("Adding all transforms"); transforms.add(ClassNameTransform.class); } else { if (config.getBoolean("Obfuscator.classname_obfuscation")) { LOGGER.fine("Adding class name transform"); transforms.add(ClassNameTransform.class); } if (config.getBoolean("Obfuscator.controlflow_obfuscation")) { LOGGER.fine("Control flow obfuscation not added, transform does not exist"); } if (config.getBoolean("Obfuscator.string_obfuscation")) { LOGGER.fine("String obfuscation not added, transform does not exist"); } if (config.getBoolean("Obfuscator.fieldname_transforms")) { LOGGER.fine("Field name obfuscation not added, transform does not exist"); } if (config.getBoolean("Obfuscator.methodname_transforms")) { LOGGER.fine("Method name obfuscation not added, transform does not exist"); } } LOGGER.info("Loaded " + transforms.size() + " transforms"); String inputFile = config.get("Obfuscator.input"); LOGGER.fine("Checking input file(s) and output directory"); String outFile = config.get("Obfuscator.out_dir"); out = new File(outFile); if (inputFile == null || inputFile.isEmpty()) { LOGGER.severe("Input file not specified in config"); throw new RuntimeException("Input file not specified"); } else { in = new File(inputFile); if (!in.exists()) { LOGGER.severe("Input file not found"); throw new RuntimeException("Input file not found"); } LOGGER.fine("Attempting to initialise classes"); if (in.isDirectory()) { try { store.init(in.listFiles(), false); } catch (IOException e) { e.printStackTrace(); } } else if (in.getName().endsWith(".class")) { try { store.init(new File[] { in }, false); } catch (IOException e) { e.printStackTrace(); } } else if (in.getName().endsWith(".jar")) { try { JarInputStream in = new JarInputStream(new FileInputStream(this.in)); store.init(in, out, this.in); in.close(); } catch (IOException e) { e.printStackTrace(); } } LOGGER.info("Loaded " + store.nodes().size() + " classes"); } if (!out.exists()) { LOGGER.fine("Attempting to make output directory"); if (!out.mkdir()) { LOGGER.severe("Could not make output directory"); throw new RuntimeException("Could not create output dir: " + out.getAbsolutePath()); } } else if (!out.isDirectory()) { LOGGER.severe("Output directory is a file"); throw new RuntimeException(out.getName() + " is not a directory, cannot output there"); } else { if (!out.canWrite()) { LOGGER.severe("Cannot write to output directory"); throw new RuntimeException("Cannot write to output dir: " + out.getAbsolutePath()); } } }
From source file:com.crawlersick.nettool.GetattchmentFromMail1.java
public GetattchmentFromMail1(String imap, String mid, String mpd, String logfilefolder, Intent localIntent, MyIntentService myis) throws IOException { this.logfilefolder = logfilefolder; this.localIntent = localIntent; this.myis = myis; this.IMapHost = imap; this.MailId = mid; this.MailPassword = mpd; fh = new FileHandler(logfilefolder + "LogFile.log"); log.addHandler(fh);/*from w w w . j a v a 2 s .c om*/ }
From source file:rentalshop.Window.java
/** * Creates new form Window/*w ww.jav a 2s. c o m*/ * * @throws SQLException * @throws MalformedURLException * @throws IOException */ public Window() throws SQLException, MalformedURLException, IOException { logg = new FileHandler("log.txt"); logger.addHandler(logg); ds = prepareDataSource(); DBUtils.tryCreateTables(ds, Window.class.getResource("rentalshop.sql")); initComponents(); updateCbxs(); logger.log(Level.INFO, "Window created"); }
From source file:net.nharyes.drivecopy.Main.java
public Main(String[] args) { // compose options composeOptions();/* www .j a v a 2 s . c o m*/ // create the command line parser CommandLineParser parser = new PosixParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); // check log option if (line.hasOption('L')) { // add file handler FileHandler handler = new FileHandler(line.getOptionValue('L')); handler.setLevel(Level.FINE); Logger.getLogger(getClass().getPackage().getName()).addHandler(handler); logger.info(String.format("Added log output file '%s'", line.getOptionValue('L'))); } // check arguments number if (line.getArgs().length == 0) throw new ParseException("Missing argument MODE"); // check mode int action = -1; if (line.getArgs()[0].equals("upload")) action = FileStorageWorkflowManager.ACTION_UPLOAD; else if (line.getArgs()[0].equals("download")) action = FileStorageWorkflowManager.ACTION_DOWNLOAD; else if (line.getArgs()[0].equals("replace")) action = FileStorageWorkflowManager.ACTION_REPLACE; if (action == -1) throw new ParseException("MODE must be 'download', 'replace' or 'upload'."); // compose BO FileBO fileBO = new FileBO(); // check directory char c = 'f'; fileBO.setDirectory(false); if (line.hasOption('d')) { c = 'd'; fileBO.setDirectory(true); } fileBO.setFile(new File(line.getOptionValue(c))); // entry name if (line.getArgs().length == 2) { // check slashes String name = line.getArgs()[1]; if (name.startsWith("/")) name = name.substring(1); if (name.endsWith("/")) name += "Untitled"; fileBO.setName(name); } else fileBO.setName(fileBO.getFile().getName()); // compression level fileBO.setCompressionLevel(Integer.parseInt(line.getOptionValue('l', "0"))); // check delete after operation fileBO.setDeleteAfter(false); if (line.hasOption('D')) fileBO.setDeleteAfter(true); // check skip revision fileBO.setSkipRevision(false); if (line.hasOption('s')) fileBO.setSkipRevision(true); // MIME type if (line.hasOption('m')) fileBO.setMimeType(line.getOptionValue('m')); // check MD5 comparison fileBO.setCheckMd5(false); if (line.hasOption('c')) fileBO.setCheckMd5(true); // check force fileBO.setForce(false); if (line.hasOption('F')) fileBO.setForce(true); // check tree fileBO.setCreateFolders(false); if (line.hasOption('t')) fileBO.setCreateFolders(true); // get Workflow Manager Injector injector; if (line.hasOption('C')) injector = Guice.createInjector(new MainModule(line.getOptionValue('C'))); else injector = Guice.createInjector(new MainModule(CONFIGURATION_FILE)); FileStorageWorkflowManager wfm = injector.getInstance(FileStorageWorkflowManager.class); // execute workflow wfm.handleWorkflow(fileBO, action); } catch (ParseException ex) { // print help HelpFormatter formatter = new HelpFormatter(); System.out.println("Drive Copy version " + VERSION); System.out.println("Copyright 2012-2013 Luca Zanconato (luca.zanconato@nharyes.net)"); System.out.println(); formatter.printHelp("java -jar " + JAR_FILE + " [OPTIONS] <MODE> [ENTRY]", DESCRIPTION + "\n", options, "\nMODE can be download/replace/upload.\nENTRY is the path of the entry in Google Drive (i.e. \"Test Folder/Another Folder/file.txt\"); if not set, the name of the local file/directory will be used."); System.out.println(); // log exception logger.log(Level.SEVERE, ex.getMessage(), ex); // exit with error System.exit(1); } catch (WorkflowManagerException ex) { // log exception logger.log(Level.SEVERE, ex.getMessage(), ex); // exit with error System.exit(1); } catch (IOException ex) { // log exception logger.log(Level.SEVERE, ex.getMessage(), ex); // exit with error System.exit(1); } catch (Exception ex) { // log exception logger.log(Level.SEVERE, ex.getMessage(), ex); // exit with error System.exit(1); } }
From source file:org.ejbca.ui.tcp.CmpTcpServer.java
public void start() throws UnknownHostException { final String cmdHandle = org.ejbca.ui.tcp.CmpTcpCommandHandler.class.getName(); myServer = new QuickServer(); myServer.setClientAuthenticationHandler(null); myServer.setBindAddr(CmpTcpConfiguration.getTCPBindAdress()); myServer.setPort(CmpTcpConfiguration.getTCPPortNumber()); myServer.setName("CMP TCP Server v " + VER); if (QuickServer.getVersionNo() >= 1.2) { LOG.info("Using 1.2 feature"); myServer.setClientBinaryHandler(cmdHandle); myServer.setClientEventHandler(cmdHandle); //reduce info to Console myServer.setConsoleLoggingToMicro(); }//w w w.j av a 2s.c o m //setup logger to log to file Logger logger = null; FileHandler txtLog = null; final String logDir = CmpTcpConfiguration.getTCPLogDir(); final File logFile = new File(logDir + "/"); if (!logFile.canRead()) { logFile.mkdir(); } try { logger = Logger.getLogger(""); logger.setLevel(Level.INFO); logger = Logger.getLogger("cmptcpserver"); logger.setLevel(Level.FINEST); txtLog = new FileHandler(logDir + "/cmptcpserver.log"); //reduce info txtLog.setFormatter(new org.quickserver.util.logging.MicroFormatter()); logger.addHandler(txtLog); myServer.setAppLogger(logger); //imp //myServer.setConsoleLoggingToMicro(); myServer.setConsoleLoggingFormatter("org.quickserver.util.logging.SimpleTextFormatter"); myServer.setConsoleLoggingLevel(Level.INFO); } catch (Exception e) { LOG.error("Could not create xmlLog FileHandler : ", e); } try { final String confFile = CmpTcpConfiguration.getTCPConfigFile(); if (!StringUtils.isEmpty(confFile)) { final Object config[] = new Object[] { confFile }; if (!myServer.initService(config)) { LOG.error("Configuration from config file " + confFile + " failed!"); } } myServer.startServer(); //myServer.getQSAdminServer().setShellEnable(true); //myServer.startQSAdminServer(); } catch (AppException e) { LOG.error("Error in server : ", e); } }
From source file:samza.samza_test.SamzaTestTask.java
@Override public void init(Config config, TaskContext context) { this.totalFlows = 0; this.myConf = config; this.mapper = new ObjectMapper(); this.windowSize = config.getInt("securitycloud.test.countWindow.batchSize"); this.windowLimit = config.getInt("securitycloud.test.countWindow.limit"); this.IPFilter = config.get("securitycloud.test.dstIP"); // this.store = (KeyValueStore<String, Integer>) context.getStore("samza-store"); try {/*from w ww. ja v a 2 s. c o m*/ fh = new FileHandler("/tmp/statsLog.txt"); Logger.getLogger("").addHandler(fh); log.addHandler(fh); log.setLevel(Level.INFO); } catch (IOException | SecurityException ex) { Logger.getLogger(SamzaTestTask.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:fr.ens.biologie.genomique.eoulsan.MainCLI.java
@Override protected Handler getLogHandler(final URI logFile) throws IOException { if (logFile == null) { throw new NullPointerException("The log file is null"); }// w ww. j a v a 2 s .co m final File file = new File(logFile); final File parentFile = file.getParentFile(); // Create parent directory if necessary if (parentFile != null && !parentFile.exists()) { if (!parentFile.mkdirs()) { throw new IOException("Unable to create directory " + parentFile + " for log file:" + logFile); } } return new FileHandler(file.getAbsolutePath()); }
From source file:edu.harvard.iq.dataverse.batch.util.LoggingUtil.java
public static Logger getJobLogger(String jobId) { try {//from w w w.j a va 2 s .c o m Logger jobLogger = Logger.getLogger("job-" + jobId); FileHandler fh; String logDir = System.getProperty("com.sun.aas.instanceRoot") + System.getProperty("file.separator") + "logs" + System.getProperty("file.separator") + "batch-jobs" + System.getProperty("file.separator"); checkCreateLogDirectory(logDir); fh = new FileHandler(logDir + "job-" + jobId + ".log"); logger.log(Level.INFO, "JOB LOG: " + logDir + "job-" + jobId + ".log"); jobLogger.addHandler(fh); fh.setFormatter(new JobLogFormatter()); return jobLogger; } catch (SecurityException e) { logger.log(Level.SEVERE, "Unable to create job logger: " + e.getMessage()); return null; } catch (IOException e) { logger.log(Level.SEVERE, "Unable to create job logger: " + e.getMessage()); return null; } }