gpt4 book ai didi

java - 从 PJSIP 示例 (PJSUA2) 中调用 LogWriter 的位置打印

转载 作者:行者123 更新时间:2023-11-30 02:03:02 25 4
gpt4 key购买 nike

对于 android 的 PJSUA2 示例,MyApp.java 类有一个日志打印机:

class MyLogWriter extends LogWriter
{
public String appLabel = "PJSUA (MyApp - MyLogWriter)";

@Override
public void write(LogEntry entry) {
Log.i(appLabel, "LW("+entry.getLevel()+") Msg: " + entry.getMsg());
}
}

从“LogWriter”类扩展:

package org.pjsip.pjsua2;

public class LogWriter {
private long swigCPtr;
protected boolean swigCMemOwn;

protected LogWriter(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}

protected static long getCPtr(LogWriter obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}

protected void finalize() {
delete();
}

public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
pjsua2JNI.delete_LogWriter(swigCPtr);
}
swigCPtr = 0;
}
}

protected void swigDirectorDisconnect() {
swigCMemOwn = false;
delete();
}

public void swigReleaseOwnership() {
swigCMemOwn = false;
pjsua2JNI.LogWriter_change_ownership(this, swigCPtr, false);
}

public void swigTakeOwnership() {
swigCMemOwn = true;
pjsua2JNI.LogWriter_change_ownership(this, swigCPtr, true);
}

public void write(LogEntry entry) {
pjsua2JNI.LogWriter_write(swigCPtr, this, LogEntry.getCPtr(entry), entry);
}

public LogWriter() {
this(pjsua2JNI.new_LogWriter(), true);
pjsua2JNI.LogWriter_director_connect(this, swigCPtr, swigCMemOwn, true);
}

}

它确实打印了一个非常完整的日志,

07-02 09:22:13.791: I/PJSUA (MyApp - MyLogWriter)(21597): LW(1) Msg: 09:22:13.788 sip_transport.  Error processing 575 bytes packet from UDP 107.170.134.248:5060 : PJSIP syntax error exception when parsing 'To' header on line 5 col 38:

据此我知道我的问题出在解析中,问题出在哪个文件中?PJSUA 有 203 个 .java 文件,其中没有一个名为“sip_transport”。

有没有办法让这个日志显示它是从哪里调用的?或者任何其他方法来找到这个解析问题的根源?

最佳答案

您可以使用线程的stacktrace获取调用方法的详细信息。

StackTraceElement caller = Thread.currentThread().getStackTrace()[1];

caller.getClassName();
caller.getMethodName();
caller.getFileName();
caller.getLineNumber();

请注意,选择 1st 索引是因为 0 是当前方法(堆栈顶部),并且它随着每个调用方法而下降。因此,您可以选择堆栈中的任何调用方。

关于java - 从 PJSIP 示例 (PJSUA2) 中调用 LogWriter 的位置打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31185094/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com