Example usage for android.util Log getStackTraceString

List of usage examples for android.util Log getStackTraceString

Introduction

In this page you can find the example usage for android.util Log getStackTraceString.

Prototype

public static String getStackTraceString(Throwable tr) 

Source Link

Document

Handy function to get a loggable stack trace from a Throwable

Usage

From source file:Main.java

static private void log(Exception e) {
    Log.i(TAG, Log.getStackTraceString(e));
}

From source file:Main.java

public static void logErrorStackTrace(Object source, Exception e, String msg) {
    String tag = source.getClass().getSimpleName();
    Log.e(tag, msg + ": " + e.getClass().getSimpleName() + ":");
    Log.e(tag, Log.getStackTraceString(e));
}

From source file:Main.java

private static String toString(Object message) {
    if (message == null) {
        return "[null]";
    }/*from w  w w .j  a v  a2 s  . c o  m*/
    if (message instanceof Throwable) {
        return Log.getStackTraceString((Throwable) message);
    }
    if (message instanceof Collection) {
        return toString((Collection) message);
    }
    return String.valueOf(message);
}

From source file:Main.java

/**
 * Wrapper around android.util.Log.println.
 *
 * @param priority Logging priority, using android.util.Log constants
 *//*w w  w.j  a v a  2 s.co m*/
public static void log(int priority, String tag, String message, Throwable tr) {
    Log.println(priority, tag, message + '\n' + Log.getStackTraceString(tr));
}

From source file:Main.java

private static void log(int priority, String tag, String message, Throwable exception) {
    if (message == null || message.length() == 0) {
        if (exception != null) {
            message = Log.getStackTraceString(exception);
        } else {//from  w  w  w  . j  a  v  a2 s. c  o  m
            // Swallow message if it's null and there's no throwable.
            return;
        }
    } else if (exception != null) {
        message += "\n" + Log.getStackTraceString(exception);
    }

    if (message.length() < 4000) {
        Log.println(priority, getCaller(tag), message);
    } else {
        // It's rare that the message will be this large, so we're ok
        // with the perf hit of splitting
        // and calling Log.println N times. It's possible but unlikely
        // that a single line will be
        // longer than 4000 characters: we're explicitly ignoring this
        // case here.
        String[] lines = message.split("\n");
        for (String line : lines) {
            Log.println(priority, getCaller(tag), line);
        }
    }
}

From source file:Main.java

/**
 * @brief      log utility/*  w  w w .  jav a2s . c o m*/
 */
static private void log(Exception e) {
    if (enableLog)
        Log.i(TAG, Log.getStackTraceString(e));
}

From source file:Main.java

public static Calendar getFinishDate(String startDate, String duration) {
    try {//from  w w  w  . j  av a  2 s  .  c  om
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
        Calendar calendarFinish = Calendar.getInstance();
        calendarFinish.setTime(sdf.parse(startDate));
        calendarFinish.add(Calendar.DATE, Integer.parseInt(duration));
        return calendarFinish;
    } catch (ParseException e) {
        Log.e("PARSE_FAIL", Log.getStackTraceString(e));
    }
    return null;
}

From source file:Main.java

public static String formatException(Exception exception) {
    String formattedString = "Internal Error";
    Log.e("App Error", exception.toString());
    Log.getStackTraceString(exception);

    String temp = exception.getMessage();

    if (temp != null && temp.length() > 0) {
        formattedString = temp.split("\\(")[0];
        if (temp != null && temp.length() > 0) {
            return formattedString;
        }// ww  w.  jav  a 2 s  . c om
    }

    return formattedString;
}

From source file:Main.java

public static void report(Throwable e) {

    if (e == null)
        return;// ww  w .  jav  a 2  s .  co  m

    try {

        //debug(e);
        warn("reporting", Log.getStackTraceString(e));

        if (eh != null) {
            eh.uncaughtException(Thread.currentThread(), e);
        }

    } catch (Exception ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private static boolean checkOp(Context context, int op) {
    final int version = Build.VERSION.SDK_INT;
    if (version >= 19) {
        AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        try {/*w w w .ja  v  a2  s  . c  o  m*/
            Class clazz = AppOpsManager.class;
            Method method = clazz.getDeclaredMethod("checkOp", int.class, int.class, String.class);
            return AppOpsManager.MODE_ALLOWED == (int) method.invoke(manager, op, Binder.getCallingUid(),
                    context.getPackageName());
        } catch (Exception e) {
            Log.e(TAG, Log.getStackTraceString(e));
        }
    } else {
        Log.e("", "Below API 19 cannot invoke!");
    }
    return false;
}