Java Code Examples for android.util.Log

The following are top voted examples for showing how to use android.util.Log. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: arduino-android   File: HomeActivity.java View source code 7 votes vote down vote up
public String getLocalIpAddress() 
{
	try 
	{
		for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();)
		{
			NetworkInterface intf = en.nextElement();
			for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();)
			{
				InetAddress inetAddress = enumIpAddr.nextElement();
				if (!inetAddress.isLoopbackAddress()) 
				{
					return inetAddress.getHostAddress().toString();
				}
			}
		}
	} 
	catch (SocketException ex) 
	{
		Log.e("SRM", ex.toString());
	}
	return null;
}
 
Example 2
Project: arduino-android   File: HeatingMonitor.java View source code 6 votes vote down vote up
private void handleTimeSlot(String key) 
{
	Date d = new Date();
	String temp;
	int day = d.getDay();
	Log.d("SRM", "d="+day);
	if (day > 0 && day < 6)
	{
	    Log.d("SRM", "weekday");
		temp = getSetting("TEMP_d" + key);
	}
	else
	{
	    Log.d("SRM", "weekend");
		temp = getSetting("TEMP_w" + key);
	}
	String hourFromS = key.substring(0,2);
	String hourToS = key.substring(2,4);
	int hourFrom = Integer.parseInt(hourFromS);
	int hourTo = Integer.parseInt(hourToS);
	int hour = d.getHours();
	if (hour >= hourFrom && hour < hourTo)
	{
		DigitalOutputs outputs = mActivity.outputs;
		int t = Integer.parseInt(temp);
		if ("C".equals(getSetting("UNITS")))
		{
			t = (t * 9) / 5 + 32;
		}
		t = t + 20; // fiddle factor  deg F - sensor gets warm in box
		outputs.setOutput(0x41, t);
	}
}
 
Example 3
Project: arduino-android   File: DigitalOutputs.java View source code 6 votes vote down vote up
public void setOutput(int op, int value)
{
	Log.i("SRM", "Setting Output" + op + " to " + value);
	int x = op * 0x100 + value;
	Beeper b = new Beeper();
	b.beep(x);
}
 
Example 4
Project: BLEConnect   File: BLESQLLiteHelper.java View source code 6 votes vote down vote up
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  Log.w(BLESQLLiteHelper.class.getName(),
      "Upgrading database from version " + oldVersion + " to "
          + newVersion + ", which will destroy all old data");
  db.execSQL("DROP TABLE IF EXISTS " + COLUMN_SESSION);
  onCreate(db);
}
 
Example 5
Project: android-CLog   File: CLog.java View source code 6 votes vote down vote up
/**
 * Send a VERBOSE log message.
 *
 * @param tag
 * @param msg
 */
public static void v(String tag, String msg) {
    if (sLevel > LEVEL_VERBOSE) {
        return;
    }
    Log.v(tag, msg);
}
 
Example 6
Project: thermospy   File: VolleyLog.java View source code 6 votes vote down vote up
/**
 * Customize the log tag for your application, so that other apps
 * using Volley don't mix their logs with yours.
 * <br />
 * Enable the log property for your tag before starting your app:
 * <br />
 * [email protected] adb shell setprop log.tag.&lt;tag&gt;}
 */
public static void setTag(String tag) {
    d("Changing log tag to %s", tag);
    TAG = tag;

    // Reinitialize the DEBUG "constant"
    DEBUG = Log.isLoggable(TAG, Log.VERBOSE);
}
 
Example 7
Project: android-CLog   File: CLog.java View source code 6 votes vote down vote up
/**
 * Send a FATAL ERROR log message
 *
 * @param tag
 * @param msg
 */
public static void f(String tag, String msg) {
    if (sLevel > LEVEL_FATAL) {
        return;
    }
    Log.wtf(tag, msg);
}
 
Example 8
Project: dlna   File: FixedAndroidHandler.java View source code 6 votes vote down vote up
/**
 * Converts a [email protected] java.util.logging.Logger} logging level into an Android one.
 *
 * @param level The [email protected] java.util.logging.Logger} logging level.
 *
 * @return The resulting Android logging level.
 */
static int getAndroidLevel(Level level) {
    int value = level.intValue();
    if (value >= 1000) { // SEVERE
        return Log.ERROR;
    } else if (value >= 900) { // WARNING
        return Log.WARN;
    } else if (value >= 800) { // INFO
        return Log.INFO;
    } else {
        return Log.DEBUG;
    }
}
 
Example 9
Project: DistSysProject   File: U.java View source code 6 votes vote down vote up
private static void logAndShowException(String tag, Exception e, Handler postHandler) {
	String exDesc = formatException(e);
	Log.e(tag, exDesc); // TODO superfluous?
	Log.e(tag, Log.getStackTraceString(e));
	if (postHandler == null)
		showToast(exDesc, Toast.LENGTH_LONG);
	else
		postToast(postHandler, exDesc, Toast.LENGTH_LONG);
}
 
Example 10
Project: android-xkcd   File: Ln.java View source code 6 votes vote down vote up
public static String logLevelToString(int loglevel) {
  switch (loglevel) {
    case Log.VERBOSE:
      return "VERBOSE";
    case Log.DEBUG:
      return "DEBUG";
    case Log.INFO:
      return "INFO";
    case Log.WARN:
      return "WARN";
    case Log.ERROR:
      return "ERROR";
    case Log.ASSERT:
      return "ASSERT";
  }

  return "UNKNOWN";
}
 
Example 11
Project: dlna   File: FixedAndroidHandler.java View source code 5 votes vote down vote up
@Override
public void publish(LogRecord record) {
    try {
        int level = getAndroidLevel(record.getLevel());
        String tag = record.getLoggerName();

        if (tag == null) {
            // Anonymous logger.
            tag = "null";
        } else {
            // Tags must be <= 23 characters.
            int length = tag.length();
            if (length > 23) {
                // Most loggers use the full class name. Try dropping the
                // package.
                int lastPeriod = tag.lastIndexOf(".");
                if (length - lastPeriod - 1 <= 23) {
                    tag = tag.substring(lastPeriod + 1);
                } else {
                    // Use last 23 chars.
                    tag = tag.substring(tag.length() - 23);
                }
            }
        }

        /* ############################################################################################

        Instead of using the perfectly fine java.util.logging API for setting the
        loggable levels, this call relies on a totally obscure "local.prop" file which you have to place on
        your device. By default, if you do not have that file and if you do not execute some magic
        "setprop" commands on your device, only INFO/WARN/ERROR is loggable. So whatever you do with
        java.util.logging.Logger.setLevel(...) doesn't have any effect. The debug messages might arrive
        here but they are dropped because you _also_ have to set the Android internal logging level with
        the aforementioned magic switches.

        Also, consider that you have to understand how a JUL logger name is mapped to the "tag" of
        the Android log. Basically, the whole cutting and cropping procedure above is what you have to
        memorize if you want to log with JUL and configure Android for debug output.

        I actually admire the pure evil of this setup, even Mr. Ceki can learn something!

        Commenting out these lines makes it all work as expected:

        if (!Log.isLoggable(tag, level)) {
            return;
        }

        ############################################################################################### */

        String message = getFormatter().format(record);
        Log.println(level, tag, message);
    } catch (RuntimeException e) {
        Log.e("AndroidHandler", "Error logging message.", e);
    }
}