Java Code Examples for android.util.Log.getStackTraceString()

The following are Jave code examples for showing how to use getStackTraceString() of the android.util.Log class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: GitHub   File: LogWrapper.java   View Source Code Vote up 6 votes
/**
 * Prints data out to the console using Android's native log mechanism.
 * @param priority Log level of the data being logged.  Verbose, Error, etc.
 * @param tag Tag for for the log data.  Can be used to organize log statements.
 * @param msg The actual message to be logged. The actual message to be logged.
 * @param tr If an exception was thrown, this can be sent along for the logging facilities
 *           to extract and print useful information.
 */
@Override
public void println(int priority, String tag, String msg, Throwable tr) {
    // There actually are log methods that don't take a msg parameter.  For now,
    // if that's the case, just convert null to the empty string and move on.
    String useMsg = msg;
    if (useMsg == null) {
        useMsg = "";
    }

    // If an exeption was provided, convert that exception to a usable string and attach
    // it to the end of the msg method.
    if (tr != null) {
        msg += "\n" + Log.getStackTraceString(tr);
    }

    // This is functionally identical to Log.x(tag, useMsg);
    // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
    Log.println(priority, tag, useMsg);

    // If this isn't the last node in the chain, move things along.
    if (mNext != null) {
        mNext.println(priority, tag, msg, tr);
    }
}
 
Example 2
Project: OpenVoiceCall-Android   File: WorkerThread.java   View Source Code Vote up 6 votes
private RtcEngine ensureRtcEngineReadyLock() {
    if (mRtcEngine == null) {
        String appId = mContext.getString(R.string.private_app_id);
        if (TextUtils.isEmpty(appId)) {
            throw new RuntimeException("NEED TO use your App ID, get your own ID at https://dashboard.agora.io/");
        }
        try {
            mRtcEngine = RtcEngine.create(mContext, appId, mEngineEventHandler.mRtcEventHandler);
        } catch (Exception e) {
            log.error(Log.getStackTraceString(e));
            throw new RuntimeException("NEED TO check rtc sdk init fatal error\n" + Log.getStackTraceString(e));
        }
        mRtcEngine.setChannelProfile(Constants.CHANNEL_PROFILE_COMMUNICATION);
        mRtcEngine.enableAudioVolumeIndication(200, 3); // 200 ms
        mRtcEngine.setLogFile(Environment.getExternalStorageDirectory()
                + File.separator + mContext.getPackageName() + "/log/agora-rtc.log");
    }
    return mRtcEngine;
}
 
Example 3
Project: OpenLive-Android   File: WorkerThread.java   View Source Code Vote up 6 votes
private RtcEngine ensureRtcEngineReadyLock() {
    if (mRtcEngine == null) {
        String appId = mContext.getString(R.string.private_app_id);
        if (TextUtils.isEmpty(appId)) {
            throw new RuntimeException("NEED TO use your App ID, get your own ID at https://dashboard.agora.io/");
        }
        try {
            mRtcEngine = RtcEngine.create(mContext, appId, mEngineEventHandler.mRtcEventHandler);
        } catch (Exception e) {
            log.error(Log.getStackTraceString(e));
            throw new RuntimeException("NEED TO check rtc sdk init fatal error\n" + Log.getStackTraceString(e));
        }
        mRtcEngine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
        mRtcEngine.enableVideo();
        mRtcEngine.setLogFile(Environment.getExternalStorageDirectory()
                + File.separator + mContext.getPackageName() + "/log/agora-rtc.log");
        mRtcEngine.enableDualStreamMode(true);
    }
    return mRtcEngine;
}
 
Example 4
Project: dab-iot   File: LogWrapper.java   View Source Code Vote up 6 votes
/**
 * Prints data out to the console using Android's native log mechanism.
 * @param priority Log level of the data being logged.  Verbose, Error, etc.
 * @param tag Tag for for the log data.  Can be used to organize log statements.
 * @param msg The actual message to be logged. The actual message to be logged.
 * @param tr If an exception was thrown, this can be sent along for the logging facilities
 *           to extract and print useful information.
 */
@Override
public void println(int priority, String tag, String msg, Throwable tr) {
    // There actually are log methods that don't take a msg parameter.  For now,
    // if that's the case, just convert null to the empty string and move on.
    String useMsg = msg;
    if (useMsg == null) {
        useMsg = "";
    }

    // If an exeption was provided, convert that exception to a usable string and attach
    // it to the end of the msg method.
    if (tr != null) {
        msg += "\n" + Log.getStackTraceString(tr);
    }

    // This is functionally identical to Log.x(tag, useMsg);
    // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
    Log.println(priority, tag, useMsg);

    // If this isn't the last node in the chain, move things along.
    if (mNext != null) {
        mNext.println(priority, tag, msg, tr);
    }
}
 
Example 5
Project: Android-Practice   File: LogWrapper.java   View Source Code Vote up 6 votes
/**
 * Prints data out to the console using Android's native log mechanism.
 * @param priority Log level of the data being logged.  Verbose, Error, etc.
 * @param tag Tag for for the log data.  Can be used to organize log statements.
 * @param msg The actual message to be logged. The actual message to be logged.
 * @param tr If an exception was thrown, this can be sent along for the logging facilities
 *           to extract and print useful information.
 */
@Override
public void println(int priority, String tag, String msg, Throwable tr) {
    // There actually are log methods that don't take a msg parameter.  For now,
    // if that's the case, just convert null to the empty string and move on.
    String useMsg = msg;
    if (useMsg == null) {
        useMsg = "";
    }

    // If an exeption was provided, convert that exception to a usable string and attach
    // it to the end of the msg method.
    if (tr != null) {
        msg += "\n" + Log.getStackTraceString(tr);
    }

    // This is functionally identical to Log.x(tag, useMsg);
    // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
    Log.println(priority, tag, useMsg);

    // If this isn't the last node in the chain, move things along.
    if (mNext != null) {
        mNext.println(priority, tag, msg, tr);
    }
}
 
Example 6
Project: SecretTalk   File: LogWrapper.java   View Source Code Vote up 6 votes
/**
 * Prints data out to the console using Android's native log mechanism.
 * @param priority Log level of the data being logged.  Verbose, Error, etc.
 * @param tag Tag for for the log data.  Can be used to organize log statements.
 * @param msg The actual message to be logged. The actual message to be logged.
 * @param tr If an exception was thrown, this can be sent along for the logging facilities
 *           to extract and print useful information.
 */
@Override
public void println(int priority, String tag, String msg, Throwable tr) {
    // There actually are log methods that don't take a msg parameter.  For now,
    // if that's the case, just convert null to the empty string and move on.
    String useMsg = msg;
    if (useMsg == null) {
        useMsg = "";
    }

    // If an exeption was provided, convert that exception to a usable string and attach
    // it to the end of the msg method.
    if (tr != null) {
        msg += "\n" + Log.getStackTraceString(tr);
    }

    // This is functionally identical to Log.x(tag, useMsg);
    // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
    Log.println(priority, tag, useMsg);

    // If this isn't the last node in the chain, move things along.
    if (mNext != null) {
        mNext.println(priority, tag, msg, tr);
    }
}
 
Example 7
Project: Agora-Android-Voice-Tutorial-1to1   File: VoiceChatViewActivity.java   View Source Code Vote up 5 votes
private void initializeAgoraEngine() {
    try {
        mRtcEngine = RtcEngine.create(getBaseContext(), getString(R.string.agora_app_id), mRtcEventHandler);
    } catch (Exception e) {
        Log.e(LOG_TAG, Log.getStackTraceString(e));

        throw new RuntimeException("NEED TO check rtc sdk init fatal error\n" + Log.getStackTraceString(e));
    }
}
 
Example 8
Project: boohee_v5.6   File: LeakCanary.java   View Source Code Vote up 5 votes
public static String leakInfo(Context context, HeapDump heapDump, AnalysisResult result,
                              boolean detailed) {
    PackageManager packageManager = context.getPackageManager();
    String packageName = context.getPackageName();
    try {
        PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
        String info = "In " + packageName + ":" + packageInfo.versionName + ":" + packageInfo
                .versionCode + ".\n";
        String detailedString = "";
        if (result.leakFound) {
            if (result.excludedLeak) {
                info = info + "* LEAK CAN BE IGNORED.\n";
            }
            info = info + "* " + result.className;
            if (!heapDump.referenceName.equals("")) {
                info = info + " (" + heapDump.referenceName + SocializeConstants.OP_CLOSE_PAREN;
            }
            info = info + " has leaked:\n" + result.leakTrace.toString() + "\n";
            if (detailed) {
                detailedString = "\n* Details:\n" + result.leakTrace.toDetailedString();
            }
        } else {
            info = result.failure != null ? info + "* FAILURE:\n" + Log.getStackTraceString
                    (result.failure) + "\n" : info + "* NO LEAK FOUND.\n\n";
        }
        return info + "* Reference Key: " + heapDump.referenceKey + "\n" + "* Device: " +
                Build.MANUFACTURER + " " + Build.BRAND + " " + Build.MODEL + " " + Build
                .PRODUCT + "\n" + "* Android Version: " + VERSION.RELEASE + " API: " +
                VERSION.SDK_INT + " LeakCanary: " + BuildConfig.LIBRARY_VERSION + "\n" + "* " +
                "Durations: watch=" + heapDump.watchDurationMs + "ms, gc=" + heapDump
                .gcDurationMs + "ms, heap dump=" + heapDump.heapDumpDurationMs + "ms, " +
                "analysis=" + result.analysisDurationMs + "ms" + "\n" + detailedString;
    } catch (NameNotFoundException e) {
        throw new RuntimeException(e);
    }
}
 
Example 9
Project: GitHub   File: MyLogImp.java   View Source Code Vote up 5 votes
@Override
public void printErrStackTrace(String s, Throwable throwable, String s1, Object... objects) {
    String log = objects == null ? s1 : String.format(s1, objects);
    if (log == null) {
        log = "";
    }
    log = log + "  " + Log.getStackTraceString(throwable);
    android.util.Log.e(s, log);
}
 
Example 10
Project: GitHub   File: AndroidPlatform.java   View Source Code Vote up 5 votes
@Override public void log(int level, String message, Throwable t) {
  int logLevel = level == WARN ? Log.WARN : Log.DEBUG;
  if (t != null) message = message + '\n' + Log.getStackTraceString(t);

  // Split by line, then ensure each line can fit into Log's maximum length.
  for (int i = 0, length = message.length(); i < length; i++) {
    int newline = message.indexOf('\n', i);
    newline = newline != -1 ? newline : length;
    do {
      int end = Math.min(newline, i + MAX_LOG_LENGTH);
      Log.println(logLevel, "OkHttp", message.substring(i, end));
      i = end;
    } while (i < newline);
  }
}
 
Example 11
Project: add_to_evernote_note   File: Cat.java   View Source Code Vote up 5 votes
private void println(int priority, String message, Throwable t) {
    if (message == null) {
        message = "";
    }

    if (t != null) {
        message += '\n' + Log.getStackTraceString(t);
    }
    Log.println(priority, mTag, message);
}
 
Example 12
Project: Agora-Video-Source-Android   File: VideoChatViewActivity.java   View Source Code Vote up 5 votes
private void initializeAgoraEngine() {
    try {
        mRtcEngine = RtcEngine.create(getBaseContext(), getString(R.string.agora_app_id), mRtcEventHandler);
    } catch (Exception e) {
        Log.e(LOG_TAG, Log.getStackTraceString(e));

        throw new RuntimeException("NEED TO check rtc sdk init fatal error\n" + Log.getStackTraceString(e));
    }
    mRtcEngine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
}
 
Example 13
Project: Dalaran   File: LogUtils.java   View Source Code Vote up 5 votes
private static void log(int level, Object o, Throwable tr) {
        if (!ENABLED) return;

        String trace = generateTrace();
        String toast = trace.split("\\(")[0];
        String message = generateMessage(o) + SEPARATOR + trace;

        if (tr != null) {
            message += "\n" + Log.getStackTraceString(tr);
        }

        switch (level) {
            case Log.VERBOSE:
                Log.v(TAG, message);
                break;
            case Log.DEBUG:
                Log.d(TAG, message);
                break;
            case Log.INFO:
                Log.i(TAG, message);
                break;
            case Log.WARN:
                Log.w(TAG, message);
//                ToastManager.show("Log.WARN\n" + toast);
                break;
            case Log.ERROR:
                Log.e(TAG, message);
//                ToastManager.show("Log.ERROR\n" + toast);
//                throw new IllegalStateException(message);
                break;
            case Log.ASSERT:
                Log.wtf(TAG, message);
//                ToastManager.show("Log.ASSERT\n" + toast);
//                throw new IllegalStateException(message);
                break;
            default:
                throw new IllegalStateException();
        }
    }
 
Example 14
Project: sctalk   File: DumpUtils.java   View Source Code Vote up 5 votes
public static void dumpStacktrace(Logger logger, String desc,
		boolean oneLine) {
	String stackTraceString = Log.getStackTraceString(new Throwable());

	if (oneLine) {
		stackTraceString = stackTraceString.replace("\n", "####");
	}
	
	logger.d("%s:%s", desc, stackTraceString);
}
 
Example 15
Project: GitHub   File: DaoLog.java   View Source Code Vote up 4 votes
public static String getStackTraceString(Throwable th) {
    return Log.getStackTraceString(th);
}
 
Example 16
Project: GitHub   File: UtilsTest.java   View Source Code Vote up 4 votes
@Test public void getStackTraceString() {
  Throwable throwable = new Throwable("test");
  String androidTraceString = Log.getStackTraceString(throwable);
  assertThat(Utils.getStackTraceString(throwable)).isEqualTo(androidTraceString);
}
 
Example 17
Project: TodoRealm   File: LogUtils.java   View Source Code Vote up 4 votes
public static String getStackTraceString(Throwable tr) {
    return Log.getStackTraceString(tr);
}
 
Example 18
Project: VirtualHook   File: VLog.java   View Source Code Vote up 4 votes
public static String getStackTraceString(Throwable tr) {
	return Log.getStackTraceString(tr);
}
 
Example 19
Project: FriendBook   File: AppException.java   View Source Code Vote up 4 votes
/**
 * 获取APP崩溃异常报告
 *
 * @param ex
 * @return
 */
private static String getCrashReport(Context context, Throwable ex) {

    StringBuilder exceptionStr = new StringBuilder();
    PackageInfo pinfo;
    try {
        pinfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        exceptionStr
                .append("Version: ")
                .append(pinfo.versionName)
                .append("\nVersionCode: ")
                .append(pinfo.versionCode);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        exceptionStr.append("\nthe application not found \n");
    }
    exceptionStr
            .append("\nAndroid: ")
            .append(android.os.Build.VERSION.RELEASE)
            .append("(")
            .append(android.os.Build.MODEL)
            .append(")\n");
    String stackTraceString = Log.getStackTraceString(ex);
    if (stackTraceString != null && stackTraceString.length() > 0) {
        exceptionStr
                .append(stackTraceString);
    } else {
        exceptionStr
                .append("\nException: ")
                .append(ex.getMessage())
                .append("\n");
        StackTraceElement[] elements = ex.getStackTrace();
        for (StackTraceElement element : elements) {
            exceptionStr
                    .append(element.toString());
        }
    }


    return exceptionStr.toString();
}
 
Example 20
Project: container   File: VLog.java   View Source Code Vote up 4 votes
public static String getStackTraceString(Throwable tr) {
	return Log.getStackTraceString(tr);
}