Here you can find the source of logErrPrint(String s)
Parameter | Description |
---|---|
s | String to be printed. |
public static void logErrPrint(String s)
//package com.java2s; //License from project: Open Source License import java.util.logging.*; import java.text.NumberFormat; public class Main { static Calendar cal = Calendar.getInstance(); private static Logger logger; private static NumberFormat formatFloat, formatInt; /**//from w w w. j av a 2s .com * logPrintErr() prints the String s to System.err with a timestamp indicating the hour and minute * it was printed. * @param s String to be printed. */ public static void logErrPrint(String s) { cal.setTimeInMillis(System.currentTimeMillis()); System.err.println(nf(cal.get(Calendar.HOUR_OF_DAY), 2) + ":" + nf(cal.get(Calendar.MINUTE), 2) + "| " + s); if (logger != null) logger.warning(s); } /** * Format floating point number for printing * * @param num * Number to format * @param lead * Minimum number of leading digits * @param digits * Number of decimal digits to show * @return Formatted number string */ static public String nf(float num, int lead, int decimal) { if (formatFloat == null) nfInitFormats(); formatFloat.setMinimumIntegerDigits(lead); formatFloat.setMaximumFractionDigits(decimal); formatFloat.setMinimumFractionDigits(decimal); return formatFloat.format(num).replace(",", "."); } static public String nf(double num, int lead, int decimal) { return nf((float) num, lead, decimal); } /** * Format floating point number for printing with maximum 3 decimal points. * * @param num * Number to format * @return Formatted number string */ static public String nf(float num) { if (formatFloat == null) nfInitFormats(); formatFloat.setMinimumIntegerDigits(1); formatFloat.setMaximumFractionDigits(3); return formatFloat.format(num).replace(",", "."); } static public String nf(double num) { return nf((float) num); } /** * Format integer number for printing, padding with zeros if number has fewer * digits than desired. * * @param num * Number to format * @param digits * Minimum number of digits to show * @return Formatted number string */ static public String nf(int num, int digits) { if (formatInt == null) nfInitFormats(); formatInt.setMinimumIntegerDigits(digits); return formatInt.format(num); } static public void nfInitFormats() { formatFloat = NumberFormat.getInstance(); formatFloat.setGroupingUsed(false); formatInt = NumberFormat.getInstance(); formatInt.setGroupingUsed(false); } }