List of usage examples for java.util.logging Level FINER
Level FINER
To view the source code for java.util.logging Level FINER.
Click Source Link
From source file:org.apache.reef.bridge.client.JobResourceUploader.java
/** * This class is invoked from Org.Apache.REEF.Client.Yarn.LegacyJobResourceUploader in .NET code. * Arguments://from w w w . j a v a2s .c o m * [0] : Local path for file. * [1] : Type for file. * [2] : Path of job submission directory * [3] : File path for output with details of uploaded resource */ public static void main(final String[] args) throws InjectionException, IOException { Validate.isTrue(args.length == 4, "Job resource uploader requires 4 args"); final File localFile = new File(args[0]); Validate.isTrue(localFile.exists(), "Local file does not exist " + localFile.getAbsolutePath()); final String fileType = args[1]; final String jobSubmissionDirectory = args[2]; final String localOutputPath = args[3]; LOG.log(Level.INFO, "Received args: LocalPath " + localFile.getAbsolutePath() + " Submission directory " + jobSubmissionDirectory + " LocalOutputPath " + localOutputPath); final Configuration configuration = Tang.Factory.getTang().newConfigurationBuilder() .bindImplementation(RuntimeClasspathProvider.class, YarnClasspathProvider.class) .bindConstructor(org.apache.hadoop.yarn.conf.YarnConfiguration.class, YarnConfigurationConstructor.class) .build(); final JobUploader jobUploader = Tang.Factory.getTang().newInjector(configuration) .getInstance(JobUploader.class); final LocalResource localResource = jobUploader.createJobFolder(jobSubmissionDirectory) .uploadAsLocalResource(localFile, LocalResourceType.valueOf(fileType)); // Output: <UploadedPath>;<LastModificationUnixTimestamp>;<ResourceSize> final URL resource = localResource.getResource(); final String outputString = String.format("%s://%s:%d%s;%d;%d", resource.getScheme(), resource.getHost(), resource.getPort(), resource.getFile(), localResource.getTimestamp(), localResource.getSize()); LOG.log(Level.INFO, "Writing output: " + outputString); try (Writer writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(localOutputPath), "utf-8"))) { writer.write(outputString); } LOG.log(Level.FINER, "Done writing output file"); }
From source file:MailHandlerDemo.java
/** * Runs the demo./*from ww w .jav a 2s . c om*/ * * @param args the command line arguments * @throws IOException if there is a problem. */ public static void main(String[] args) throws IOException { List<String> l = Arrays.asList(args); if (l.contains("/?") || l.contains("-?") || l.contains("-help")) { LOGGER.info("Usage: java MailHandlerDemo " + "[[-all] | [-body] | [-custom] | [-debug] | [-low] " + "| [-simple] | [-pushlevel] | [-pushfilter] " + "| [-pushnormal] | [-pushonly]] " + "\n\n" + "-all\t\t: Execute all demos.\n" + "-body\t\t: An email with all records and only a body.\n" + "-custom\t\t: An email with attachments and dynamic names.\n" + "-debug\t\t: Output basic debug information about the JVM " + "and log configuration.\n" + "-low\t\t: Generates multiple emails due to low capacity." + "\n" + "-simple\t\t: An email with all records with body and " + "an attachment.\n" + "-pushlevel\t: Generates high priority emails when the" + " push level is triggered and normal priority when " + "flushed.\n" + "-pushFilter\t: Generates high priority emails when the " + "push level and the push filter is triggered and normal " + "priority emails when flushed.\n" + "-pushnormal\t: Generates multiple emails when the " + "MemoryHandler push level is triggered. All generated " + "email are sent as normal priority.\n" + "-pushonly\t: Generates multiple emails when the " + "MemoryHandler push level is triggered. Generates high " + "priority emails when the push level is triggered and " + "normal priority when flushed.\n"); } else { final boolean debug = init(l); //may create log messages. try { LOGGER.log(Level.FINEST, "This is the finest part of the demo.", new MessagingException("Fake JavaMail issue.")); LOGGER.log(Level.FINER, "This is the finer part of the demo.", new NullPointerException("Fake bug.")); LOGGER.log(Level.FINE, "This is the fine part of the demo."); LOGGER.log(Level.CONFIG, "Logging config file is {0}.", getConfigLocation()); LOGGER.log(Level.INFO, "Your temp directory is {0}, " + "please wait...", getTempDir()); try { //Waste some time for the custom formatter. Thread.sleep(3L * 1000L); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } LOGGER.log(Level.WARNING, "This is a warning.", new FileNotFoundException("Fake file chooser issue.")); LOGGER.log(Level.SEVERE, "The end of the demo.", new IOException("Fake access denied issue.")); } finally { closeHandlers(); } //Force parse errors. This does have side effects. if (debug && getConfigLocation() != null) { LogManager.getLogManager().readConfiguration(); } } }
From source file:com.frostvoid.trekwar.server.TrekwarServer.java
public static void main(String[] args) { // load language try {//from w w w . j ava 2 s . c o m lang = new Language(Language.ENGLISH); } catch (IOException ioe) { System.err.println("FATAL ERROR: Unable to load language file!"); System.exit(1); } System.out.println(lang.get("trekwar_server") + " " + VERSION); System.out.println("==============================================".substring(0, lang.get("trekwar_server").length() + 1 + VERSION.length())); // Handle parameters Options options = new Options(); options.addOption(OptionBuilder.withArgName("file").withLongOpt("galaxy").hasArg() .withDescription("the galaxy file to load").create("g")); //"g", "galaxy", true, "the galaxy file to load"); options.addOption(OptionBuilder.withArgName("port number").withLongOpt("port").hasArg() .withDescription("the port number to bind to (default 8472)").create("p")); options.addOption(OptionBuilder.withArgName("number").withLongOpt("save-interval").hasArg() .withDescription("how often (in turns) to save the galaxy to disk (default: 5)").create("s")); options.addOption(OptionBuilder.withArgName("log level").withLongOpt("log").hasArg() .withDescription("sets the log level: ALL, FINEST, FINER, FINE, CONFIG, INFO, WARNING, SEVERE, OFF") .create("l")); options.addOption("h", "help", false, "prints this help message"); CommandLineParser cliParser = new BasicParser(); try { CommandLine cmd = cliParser.parse(options, args); String portStr = cmd.getOptionValue("p"); String galaxyFileStr = cmd.getOptionValue("g"); String saveIntervalStr = cmd.getOptionValue("s"); String logLevelStr = cmd.getOptionValue("l"); if (cmd.hasOption("h")) { HelpFormatter help = new HelpFormatter(); help.printHelp("TrekwarServer", options); System.exit(0); } if (cmd.hasOption("g") && galaxyFileStr != null) { galaxyFileName = galaxyFileStr; } else { throw new ParseException("galaxy file not specified"); } if (cmd.hasOption("p") && portStr != null) { port = Integer.parseInt(portStr); if (port < 1 || port > 65535) { throw new NumberFormatException(lang.get("port_number_out_of_range")); } } else { port = 8472; } if (cmd.hasOption("s") && saveIntervalStr != null) { saveInterval = Integer.parseInt(saveIntervalStr); if (saveInterval < 1 || saveInterval > 100) { throw new NumberFormatException("Save Interval out of range (1-100)"); } } else { saveInterval = 5; } if (cmd.hasOption("l") && logLevelStr != null) { if (logLevelStr.equalsIgnoreCase("finest")) { LOG.setLevel(Level.FINEST); } else if (logLevelStr.equalsIgnoreCase("finer")) { LOG.setLevel(Level.FINER); } else if (logLevelStr.equalsIgnoreCase("fine")) { LOG.setLevel(Level.FINE); } else if (logLevelStr.equalsIgnoreCase("config")) { LOG.setLevel(Level.CONFIG); } else if (logLevelStr.equalsIgnoreCase("info")) { LOG.setLevel(Level.INFO); } else if (logLevelStr.equalsIgnoreCase("warning")) { LOG.setLevel(Level.WARNING); } else if (logLevelStr.equalsIgnoreCase("severe")) { LOG.setLevel(Level.SEVERE); } else if (logLevelStr.equalsIgnoreCase("off")) { LOG.setLevel(Level.OFF); } else if (logLevelStr.equalsIgnoreCase("all")) { LOG.setLevel(Level.ALL); } else { System.err.println("ERROR: invalid log level: " + logLevelStr); System.err.println("Run again with -h flag to see valid log level values"); System.exit(1); } } else { LOG.setLevel(Level.INFO); } // INIT LOGGING try { LOG.setUseParentHandlers(false); initLogging(); } catch (IOException ex) { System.err.println("Unable to initialize logging to file"); System.err.println(ex); System.exit(1); } } catch (Exception ex) { System.err.println("ERROR: " + ex.getMessage()); System.err.println("use -h for help"); System.exit(1); } LOG.log(Level.INFO, "Trekwar2 server " + VERSION + " starting up"); // LOAD GALAXY File galaxyFile = new File(galaxyFileName); if (galaxyFile.exists()) { try { long timer = System.currentTimeMillis(); LOG.log(Level.INFO, "Loading galaxy file {0}", galaxyFileName); ObjectInputStream ois = new ObjectInputStream(new FileInputStream(galaxyFile)); galaxy = (Galaxy) ois.readObject(); timer = System.currentTimeMillis() - timer; LOG.log(Level.INFO, "Galaxy file loaded in {0} ms", timer); ois.close(); } catch (IOException ioe) { LOG.log(Level.SEVERE, "IO error while trying to load galaxy file", ioe); } catch (ClassNotFoundException cnfe) { LOG.log(Level.SEVERE, "Unable to find class while loading galaxy", cnfe); } } else { System.err.println("Error: file " + galaxyFileName + " not found"); System.exit(1); } // if turn == 0 (start of game), execute first turn to update fog of war. if (galaxy.getCurrentTurn() == 0) { TurnExecutor.executeTurn(galaxy); } LOG.log(Level.INFO, "Current turn : {0}", galaxy.getCurrentTurn()); LOG.log(Level.INFO, "Turn speed : {0} seconds", galaxy.getTurnSpeed() / 1000); LOG.log(Level.INFO, "Save Interval : {0}", saveInterval); LOG.log(Level.INFO, "Users / max : {0} / {1}", new Object[] { galaxy.getUserCount(), galaxy.getMaxUsers() }); // START SERVER try { server = new ServerSocket(port); LOG.log(Level.INFO, "Server listening on port {0}", port); } catch (BindException be) { LOG.log(Level.SEVERE, "Error: Unable to bind to port {0}", port); System.err.println(be); System.exit(1); } catch (IOException ioe) { LOG.log(Level.SEVERE, "Error: IO error while binding to port {0}", port); System.err.println(ioe); System.exit(1); } galaxy.startup(); Thread timerThread = new Thread(new Runnable() { @Override @SuppressWarnings("SleepWhileInLoop") public void run() { while (true) { try { Thread.sleep(1000); // && galaxy.getLoggedInUsers().size() > 0 will make server pause when nobody is logged in (TESTING) if (System.currentTimeMillis() > galaxy.nextTurnDate) { StringBuffer loggedInUsers = new StringBuffer(); for (User u : galaxy.getLoggedInUsers()) { loggedInUsers.append(u.getUsername()).append(", "); } long time = TurnExecutor.executeTurn(galaxy); LOG.log(Level.INFO, "Turn {0} executed in {1} ms", new Object[] { galaxy.getCurrentTurn(), time }); LOG.log(Level.INFO, "Logged in users: " + loggedInUsers.toString()); LOG.log(Level.INFO, "===================================================================================="); if (galaxy.getCurrentTurn() % saveInterval == 0) { saveGalaxy(); } galaxy.lastTurnDate = System.currentTimeMillis(); galaxy.nextTurnDate = galaxy.lastTurnDate + galaxy.turnSpeed; } } catch (InterruptedException e) { LOG.log(Level.SEVERE, "Error in main server loop, interrupted", e); } } } }); timerThread.start(); // ACCEPT CONNECTIONS AND DELEGATE TO CLIENT SESSIONS while (true) { Socket clientConnection; try { clientConnection = server.accept(); ClientSession c = new ClientSession(clientConnection, galaxy); Thread t = new Thread(c); t.start(); } catch (IOException ex) { LOG.log(Level.SEVERE, "IO Exception while trying to handle incoming client connection", ex); } } }
From source file:org.apache.oodt.cas.filemgr.datatransfer.LocalDataTransferer.java
/** * @param args/*from w ww.ja v a 2 s. c o m*/ */ public static void main(String[] args) throws DataTransferException, IOException, URISyntaxException { String usage = "LocalFileTransfer --productName <name> --productRepo <repo> [--dir <dirRef>] [--files <origRef 1>...<origRef N>]\n"; MimeTypes mimeTypeRepo; try { mimeTypeRepo = MimeTypesFactory .create(System.getProperty("org.apache.oodt.cas.filemgr.mime.type.repository")); } catch (MimeTypeException e) { LOG.log(Level.SEVERE, e.getMessage()); throw new IOException(e.getMessage()); } String productName = null; String productRepo = null; String transferType = null; Reference dirReference = null; List<Reference> fileReferences = null; for (int i = 0; i < args.length; i++) { if (args[i].equals("--dir")) { transferType = "dir"; dirReference = new Reference(); dirReference.setOrigReference(new File(new URI(args[++i])).toURI().toString()); LOG.log(Level.FINER, "LocalFileTransfer.main: Generated orig reference: " + dirReference.getOrigReference()); } else if (args[i].equals("--files")) { transferType = "files"; fileReferences = new Vector<Reference>(); for (int j = i + 1; j < args.length; j++) { LOG.log(Level.FINER, "LocalFileTransfer.main: Adding file ref: " + args[j]); fileReferences.add(new Reference(args[j], null, new File(args[j]).length(), mimeTypeRepo.getMimeType(args[j]))); } } else if (args[i].equals("--productName")) { productName = args[++i]; } else if (args[i].equals("--productRepo")) { productRepo = args[++i]; } } if (transferType == null || (((transferType.equals("dir") && dirReference == null) || (transferType.equals("files") && fileReferences == null) || (!(transferType.equals("dir") || transferType.equals("files"))) || productName == null || productRepo == null))) { System.err.println(usage); System.exit(1); } // construct a new Product Product p = new Product(); p.setProductName(productName); if (transferType.equals("dir")) { p.setProductStructure(Product.STRUCTURE_HIERARCHICAL); dirReference.setDataStoreReference(new File(new URI(productRepo)).toURI().toURL().toExternalForm() + URLEncoder.encode(p.getProductName(), "UTF-8") + "/"); p.getProductReferences().add(dirReference); /* we'll do a simple versioning scheme ourselves: no versioning! */ p.getProductReferences().addAll( VersioningUtils.getReferencesFromDir(new File(new URI(dirReference.getOrigReference())))); VersioningUtils.createBasicDataStoreRefsHierarchical(p.getProductReferences()); } else if (transferType.equals("files")) { p.setProductStructure("Flat"); p.getProductReferences().addAll(fileReferences); VersioningUtils.createBasicDataStoreRefsFlat(productName, productRepo, p.getProductReferences()); } DataTransfer transfer = new LocalDataTransferer(); transfer.transferProduct(p); }
From source file:MyClass.java
public boolean myMethod(int p1, Object p2) { Logger logger = Logger.getLogger("com.mycompany.MyClass"); if (logger.isLoggable(Level.FINER)) { logger.entering(this.getClass().getName(), "myMethod", new Object[] { new Integer(p1), p2 }); }//from w w w .ja va 2 s .com System.out.println("Method body"); boolean result = true; if (logger.isLoggable(Level.FINER)) { logger.exiting(this.getClass().getName(), "myMethod", new Boolean(result)); logger.exiting(this.getClass().getName(), "myMethod"); } return result; }
From source file:org.exfio.weavedroid.util.Log.java
public static Level toJavaUtilLevel(String level) throws IllegalArgumentException { if (level.toLowerCase().equals("error")) { return java.util.logging.Level.SEVERE; } else if (level.toLowerCase().equals("warn")) { return java.util.logging.Level.WARNING; } else if (level.toLowerCase().equals("info")) { return java.util.logging.Level.INFO; } else if (level.toLowerCase().equals("debug")) { return java.util.logging.Level.FINE; } else if (level.toLowerCase().equals("trace")) { return java.util.logging.Level.FINER; } else {// ww w . j av a 2s. c o m throw new IllegalArgumentException(String.format("Log level '%s' not recognised", level)); } }
From source file:org.dojotoolkit.zazl.internal.XMLHttpRequestUtils.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static String xhrRequest(String shrDataString) { InputStream is = null;//w w w.j a v a2 s . co m String json = null; try { logger.logp(Level.FINER, XMLHttpRequestUtils.class.getName(), "xhrRequest", "shrDataString [" + shrDataString + "]"); Map<String, Object> xhrData = (Map<String, Object>) JSONParser.parse(new StringReader(shrDataString)); String url = (String) xhrData.get("url"); String method = (String) xhrData.get("method"); List headers = (List) xhrData.get("headers"); URL requestURL = createURL(url); URI uri = new URI(requestURL.toString()); HashMap httpMethods = new HashMap(7); httpMethods.put("DELETE", new HttpDelete(uri)); httpMethods.put("GET", new HttpGet(uri)); httpMethods.put("HEAD", new HttpHead(uri)); httpMethods.put("OPTIONS", new HttpOptions(uri)); httpMethods.put("POST", new HttpPost(uri)); httpMethods.put("PUT", new HttpPut(uri)); httpMethods.put("TRACE", new HttpTrace(uri)); HttpUriRequest request = (HttpUriRequest) httpMethods.get(method.toUpperCase()); if (request.equals(null)) { throw new Error("SYNTAX_ERR"); } for (Object header : headers) { StringTokenizer st = new StringTokenizer((String) header, ":"); String name = st.nextToken(); String value = st.nextToken(); request.addHeader(name, value); } HttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(request); Map headerMap = new HashMap(); HeaderIterator headerIter = response.headerIterator(); while (headerIter.hasNext()) { Header header = headerIter.nextHeader(); headerMap.put(header.getName(), header.getValue()); } int status = response.getStatusLine().getStatusCode(); String statusText = response.getStatusLine().toString(); is = response.getEntity().getContent(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = null; StringBuffer sb = new StringBuffer(); while ((line = br.readLine()) != null) { sb.append(line); sb.append('\n'); } Map m = new HashMap(); m.put("status", new Integer(status)); m.put("statusText", statusText); m.put("responseText", sb.toString()); m.put("headers", headerMap.toString()); StringWriter w = new StringWriter(); JSONSerializer.serialize(w, m); json = w.toString(); logger.logp(Level.FINER, XMLHttpRequestUtils.class.getName(), "xhrRequest", "json [" + json + "]"); } catch (Throwable e) { logger.logp(Level.SEVERE, XMLHttpRequestUtils.class.getName(), "xhrRequest", "Failed request for [" + shrDataString + "]", e); } finally { if (is != null) { try { is.close(); } catch (IOException e) { } } } return json; }
From source file:org.geoserver.importer.DataFormat.java
/** * looks up a format based on file extension. *//* w w w . jav a 2s .c o m*/ public static DataFormat lookup(File file) { FileData fileData = new FileData(file); for (DataFormat df : GeoServerExtensions.extensions(DataFormat.class)) { try { if (df.canRead(fileData)) { return df; } } catch (IOException e) { LOG.log(Level.FINER, String.format("Error checking if format %s can read file %s, " + df.getName(), file.getPath()), e); } } //look for a datastore that can handle the file String ext = FilenameUtils.getExtension(file.getName()); FileDataStoreFactorySpi factory = FileDataStoreFinder.getDataStoreFactory(ext); if (factory != null) { return new DataStoreFormat(factory); } //look for a gridformat that can handle the file Set<AbstractGridFormat> formats = GridFormatFinder.findFormats(file); AbstractGridFormat format = null; // in the case of 2 formats, let's ensure any ambiguity that cannot // be resolved is an error to prevent spurious bugs related to // the first format that is found being returned (and this can vary // to to hashing in the set) if (formats.size() > 1) { for (AbstractGridFormat f : formats) { // prefer GeoTIFF over WorldImageFormat if ("GeoTIFF".equals(f.getName())) { format = f; break; } } if (format == null) { throw new RuntimeException("multiple formats found but not handled " + formats); } } else if (formats.size() == 1) { format = formats.iterator().next(); } if (format != null && !(format instanceof UnknownFormat)) { return new GridFormat(format); } return null; }
From source file:comp.web.core.DataUtil.java
public List<Product> getProds(String cat, String prod, String from, String to) { logger.log(Level.FINER, "get prods with filter {0} {1} {2} {3}", new Object[] { cat, prod, from, to }); if (StringUtils.isBlank(cat) && StringUtils.isBlank(prod) && StringUtils.isBlank(from) && StringUtils.isBlank(to)) { return Collections.emptyList(); }/*from ww w . ja va2s . com*/ String cat1 = StringUtils.stripToEmpty(cat) + "%"; String prod1 = StringUtils.stripToEmpty(prod) + "%"; double from1 = StringUtils.isNumeric(from) ? Double.parseDouble(from) : Double.MIN_VALUE; double to1 = StringUtils.isNumeric(to) ? Double.parseDouble(to) : Double.MAX_VALUE; EntityManager em = createEM(); // EntityTransaction tx = em.getTransaction(); // tx.begin(); List<Product> products = em.createNamedQuery("priceList", Product.class).setParameter("cat", cat1) .setParameter("prod", prod1).setParameter("from", from1).setParameter("to", to1).getResultList(); // tx.commit(); em.close(); logger.log(Level.FINER, "get prods result size {0}", products.size()); return products; }
From source file:jshm.util.Crypto.java
public static String decrypt(String cipherText) { LOG.finest("entered Crypto.decrypt()"); LOG.finer("Base64 decoding cipherText"); try {/* w w w .j a va 2s . com*/ cipherText = new String(Base64.decodeBase64(cipherText.getBytes())); } catch (ArrayIndexOutOfBoundsException e) { // this is only necessary to deal with passwords that were // previously encoded via the old javax.crypto.* method LOG.info("Clearing password to handle new storage mechanism"); LOG.log(Level.FINER, "Exception from old password", e); cipherText = ""; } LOG.finest("exiting Crypto.decrypt()"); return cipherText; }