List of usage examples for java.util.logging Logger log
public void log(Level level, Throwable thrown, Supplier<String> msgSupplier)
From source file:moe.encode.airblock.commands.contrib.annotations.AnnotationCommand.java
public static void throwError(String message, Throwable throwable, Executor executor) { Logger logger = executor.getEnvironment().getBackend().getLogger(); if (logger != null) { logger.log(Level.SEVERE, message, throwable); } else {/*w w w. j a va 2 s. c o m*/ System.err.println(message); throwable.printStackTrace(); } }
From source file:bizlogic.Sensors.java
public static void list(Connection DBcon) throws IOException, ParseException, SQLException { Statement st = null;//from w ww . j av a2s. c o m ResultSet rs = null; try { st = DBcon.createStatement(); rs = st.executeQuery("SELECT * FROM USERCONF.SENSORLIST"); } catch (SQLException ex) { Logger lgr = Logger.getLogger(Sensors.class.getName()); lgr.log(Level.SEVERE, ex.getMessage(), ex); } try { FileWriter sensorsFile = new FileWriter("/var/lib/tomcat8/webapps/ROOT/Records/sensors.json"); sensorsFile.write(""); sensorsFile.flush(); JSONParser parser = new JSONParser(); JSONObject Records = new JSONObject(); JSONObject operation_Obj = new JSONObject(); JSONObject operand_Obj = new JSONObject(); JSONObject unit_Obj = new JSONObject(); JSONObject name_Obj = new JSONObject(); JSONObject ip_Obj = new JSONObject(); JSONObject port_Obj = new JSONObject(); int _total = 0; JSONArray sensorList = new JSONArray(); while (rs.next()) { JSONObject sensor_Obj = new JSONObject(); int id = rs.getInt("sensor_id"); String operation = rs.getString("operation"); int operand = rs.getInt("operand"); String unit = rs.getString("unit"); String name = rs.getString("name"); String ip = rs.getString("IP"); int port = rs.getInt("port"); sensor_Obj.put("recid", id); sensor_Obj.put("operation", operation); sensor_Obj.put("operand", operand); sensor_Obj.put("unit", unit); sensor_Obj.put("name", name); sensor_Obj.put("IP", ip); sensor_Obj.put("port", port); sensorList.add(sensor_Obj); _total++; } rs.close(); Records.put("total", _total); Records.put("records", sensorList); sensorsFile.write(Records.toJSONString()); sensorsFile.flush(); sensorsFile.close(); } catch (IOException ex) { Logger.getLogger(Sensors.class.getName()).log(Level.WARNING, null, ex); } }
From source file:eu.trentorise.opendata.commons.test.jackson.OdtJacksonTester.java
/** * Tests that the provided object can be converted to json and * reconstructed. Also logs the json with the provided logger at FINE * level./*from w w w. ja va 2 s .c o m*/ * * @return the reconstructed object */ public static <T> T testJsonConv(ObjectMapper om, Logger logger, @Nullable T obj) { checkNotNull(om); checkNotNull(logger); T recObj; try { String json = om.writeValueAsString(obj); logger.log(Level.FINE, "json = {0}", json); Object ret = om.readValue(json, obj.getClass()); recObj = (T) ret; } catch (Exception ex) { throw new RuntimeException(ex); } assertEquals(obj, recObj); return recObj; }
From source file:net.daboross.bukkitdev.skywars.gist.GistReport.java
public static String gistText(Logger logger, String text) { URL postUrl;//w w w . j av a 2 s . co m try { postUrl = new URL("https://api.github.com/gists"); } catch (MalformedURLException ex) { logger.log(Level.FINE, "Non severe error encoding api.github.com URL", ex); return null; } URLConnection connection; try { connection = postUrl.openConnection(); } catch (IOException ex) { logger.log(Level.FINE, "Non severe error opening api.github.com connection", ex); return null; } connection.setDoOutput(true); connection.setDoInput(true); JSONStringer outputJson = new JSONStringer(); try { outputJson.object().key("description").value("SkyWars debug").key("public").value("false").key("files") .object().key("report.md").object().key("content").value(text).endObject().endObject() .endObject(); } catch (JSONException ex) { logger.log(Level.FINE, "Non severe error while writing report", ex); return null; } String jsonOuptutString = outputJson.toString(); try (OutputStream outputStream = connection.getOutputStream()) { try (OutputStreamWriter requestWriter = new OutputStreamWriter(outputStream)) { requestWriter.append(jsonOuptutString); requestWriter.close(); } } catch (IOException ex) { logger.log(Level.FINE, "Non severe error writing report", ex); return null; } JSONObject inputJson; try { inputJson = new JSONObject(readConnection(connection)); } catch (JSONException | IOException unused) { logger.log(Level.FINE, "Non severe error while reading response for report.", unused); return null; } String resultUrl = inputJson.optString("html_url", null); return resultUrl == null ? null : shortenURL(logger, resultUrl); }
From source file:eu.trentorise.opendata.commons.test.jackson.TodJacksonTester.java
/** * Tests that the provided object can be converted to json and * reconstructed. Also logs the json with the provided logger at FINE level. * * @return the reconstructed object//from ww w. ja v a 2 s.c om */ public static <T> T testJsonConv(ObjectMapper om, Logger logger, @Nullable T obj) { checkNotNull(om); checkNotNull(logger); T recObj; String json; try { json = om.writeValueAsString(obj); logger.log(Level.FINE, "json = {0}", json); } catch (Exception ex) { throw new RuntimeException("FAILED SERIALIZING!", ex); } try { Object ret = om.readValue(json, obj.getClass()); recObj = (T) ret; } catch (Exception ex) { throw new RuntimeException("FAILED DESERIALIZING!", ex); } assertEquals(obj, recObj); return recObj; }
From source file:io.dacopancm.socketdcm.helper.HelperUtil.java
public static void PrintAllThreads() { Logger logger = Logger.getLogger("practical"); Thread[] ths = HelperUtil.getAllThreads(); logger.log(Level.WARNING, "Thread activos {0}", ths.length); for (Thread th : ths) { //logger.log(Level.INFO, "Thread activo {0},{1}", new Object[]{th.getId(), th.getName()}); }//from w ww . j a va 2 s. c o m }
From source file:bizlogic.Records.java
public static void add(Connection DBcon, String sensor_name, String smpl_interval, String running, String name) throws SQLException { String isRunning;// w ww .j a v a2s . co m Statement st; ResultSet rs = null; try { st = DBcon.createStatement(); rs = st.executeQuery("SELECT * FROM USERCONF.SENSORLIST WHERE NAME = '" + sensor_name + "' "); } catch (SQLException ex) { Logger lgr = Logger.getLogger(Records.class.getName()); lgr.log(Level.SEVERE, ex.getMessage(), ex); } rs.next(); int id = rs.getInt("sensor_id"); String sql_statement; if (running.equals("true")) { isRunning = "B'1'"; } else { isRunning = "B'0'"; } st = DBcon.createStatement(); sql_statement = "INSERT INTO USERCONF.LOG_LIST(SENSOR_ID, SMPL_INTERVAL, RUNNING, NAME) " + "VALUES (" + id + ", " + smpl_interval + ", " + isRunning + ", " + "'" + name + "'" + " );"; System.out.println(sql_statement); st.clearBatch(); st = DBcon.createStatement(); DBcon.createStatement(); st.executeUpdate(sql_statement); }
From source file:eu.trentorise.opendata.commons.test.jackson.TodJacksonTester.java
/** * Tests that the provided object can be converted to json and reconstructed * as type T. Also logs the json with the provided logger at FINE level. * * @return the reconstructed object//from www.j av a2 s. c o m */ public static <T> T testJsonConv(ObjectMapper om, Logger logger, @Nullable Object obj, Class<T> targetClass) { checkNotNull(om); checkNotNull(logger); T recObj; String json; try { json = om.writeValueAsString(obj); logger.log(Level.FINE, "json = {0}", json); } catch (Exception ex) { throw new RuntimeException("FAILED SERIALIZING!", ex); } try { Object ret = om.readValue(json, targetClass); recObj = (T) ret; } catch (Exception ex) { throw new RuntimeException("FAILED DESERIALIZING!", ex); } assertEquals(obj, recObj); return recObj; }
From source file:net.daboross.bukkitdev.skywars.gist.GistReport.java
public static String shortenURL(Logger logger, String url) { URL requestUrl;//from w ww.j a va 2s . c om try { requestUrl = new URL("http://is.gd/create.php?format=simple&url=" + URLEncoder.encode(url, "UTF-8")); } catch (MalformedURLException | UnsupportedEncodingException ex) { logger.log(Level.FINE, "Non severe error encoding is.gd URL", ex); return url; } URLConnection connection; try { connection = requestUrl.openConnection(); return readConnection(connection); } catch (IOException ex) { logger.log(Level.FINE, "Non severe error getting is.gd response", ex); return url; } }
From source file:bizlogic.Records.java
public static void writeCSV(Connection DBcon, String record_id) throws SQLException { Statement st;// www . j a va 2 s. c om ResultSet rs = null; System.out.println("WriteCSV started"); try { st = DBcon.createStatement(); rs = st.executeQuery("SELECT * FROM PUBLIC.t" + record_id); System.out.println("Result set read finished"); } catch (SQLException ex) { Logger lgr = Logger.getLogger(Records.class.getName()); lgr.log(Level.SEVERE, ex.getMessage(), ex); } try { String DELIMITER = ","; String NEW_LINE = "\n"; String FILE_HEADER = "Time,Series"; System.out.println("Delete old file"); FileWriter csvFile = new FileWriter("/var/lib/tomcat8/webapps/ROOT/Records/Data/" + record_id + ".csv"); //BufferedWriter csvFile = new BufferedWriter( // new OutputStreamWriter(new FileOutputStream(new File( // "/var/lib/tomcat8/webapps/ROOT/Records/Data/" + // record_id + ".csv")))); csvFile.write(""); csvFile.append(FILE_HEADER); csvFile.append(NEW_LINE); Calendar calendar = new GregorianCalendar(); System.out.println("Writing file..."); while (rs.next()) { long time_stamp = rs.getLong("time"); double value = rs.getDouble("value"); String _year; String _month; String _day; String _hour; String _min; String _sec; calendar.setTimeInMillis(time_stamp); _year = Integer.toString(calendar.get(Calendar.YEAR)); _month = Integer.toString(calendar.get(Calendar.MONTH) + 1); _day = Integer.toString(calendar.get(Calendar.DAY_OF_MONTH)); _hour = Integer.toString(calendar.get(Calendar.HOUR_OF_DAY)); _min = Integer.toString(calendar.get(Calendar.MINUTE)); _sec = Integer.toString(calendar.get(Calendar.SECOND)); csvFile.append(_year + "/" + _month + "/" + _day + " " + _hour + ":" + _min + ":" + _sec + DELIMITER + Double.toString(value) + NEW_LINE); //new Date("2009/07/19 12:34:56") } System.out.print("File written"); rs.close(); //csvFile.flush(); csvFile.close(); } catch (IOException ex) { Logger.getLogger(Records.class.getName()).log(Level.WARNING, null, ex); } }