Android的logcat的非常奇怪的现象越来越空字符串时, [英] Android Logcat very strange behavior when getting empty string

查看:142
本文介绍了Android的logcat的非常奇怪的现象越来越空字符串时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我碰到一些奇怪的事情,让我失去了一些时间。我一直在尝试打印包含字符串元素的ArrayList的内容,有时候,一个元素可以包含一个空字符串,这是好的,绝对我的意图。 所以,我有这样的事情:

So I came across something strange that made me loose some time. I have been trying to print the content of an ArrayList containing string elements, sometimes, an element might contain an empty string, which is fine and absolutely my intention. So I have something like this:

List<String> l = new ArrayList<String>();

//adding strings in l, sometimes it's an empty string

for (int i=0; i < l.size(); i++) {
    Log.w("element in l : ", l.get(i));
}

所以在这里,当回路会撞到空字符串,logcat中根本就没有打算将其打印出来,但(这里是我的困惑的根目录),如果你有一个消息之后未能显示的,突然失败的消息将显示为,如果它含有新的logcat的消息。例如,如果你尝试登录这样一个空字符串

So here, when the loop is gonna hit the empty string, logcat is simply NOT going to print it out BUT (and here is the root of my confusion), if you have a message following the one that failed to display, suddenly the failed message is going to show up as if it contained the new logcat message. For example if you try logging an empty string like this

Log.w(TAG,  <empty string here>);

logcat的是要输出什么起初,那么,当它有一个新的消息,以显示这是它打印出来(在这种情况下,新的消息是关于AudioTrack一些警告):

Logcat is going to output nothing at first, then, when it has a NEW message to display this is what it prints out (in this case the new message is some warning about AudioTrack):

08-21 17:06:02.265  13047-13047/company.myapp W/TAG﹕ [ 08-21 17:06:05.411   766:  937 W/AudioTrack ]
    AUDIO_OUTPUT_FLAG_FAST denied by client

我想知道这是如何发生的,也许它可以帮助别人得不到的超级困惑像我一样。我想尝试登陆一个空字符串触发某种缓冲,坐在那里,直到它得到的东西打印,这是一个错误?

I'm interested in knowing how this happens, maybe it can help someone else not getting super confused like I did. I suppose trying to log an empty string triggers some kind of buffer that sits there until it gets something to print, is this a bug?

推荐答案

这是一个有趣的问题。我只是想这LogRabbit和我能看到同样的结果。

That is an interesting question. I just tried this in LogRabbit and am able to see the same result.

我参加了一个快速浏览通过Android源代码,看到Log.W(...)结束了在本土code和中的 logd_write.c

I took a quick browse through the android source and see that Log.W(...) ends up in native code and getting handled in logd_write.c

这基本上是将数据写入到/ dev /日志/主(或其他日志之一)

This basically writes the data to /dev/log/main (or one of the other logs)

您可以获取这些日志是这样的:

You can get those logs like this:

adb pull /dev/log/events .
adb pull /dev/log/main .
adb pull /dev/log/radio .
adb pull /dev/log/system .

您需要preSS CNTL-C,否则副本会发生下去。

You will need to press cntl-C otherwise the copy will happen forever.

展望原始日志中的/ dev /日志/主我看到的消息也被记录到日志:

Looking in the raw log in /dev/log/main I see the message does get logged:

 <8b>F×U^_<8c>^Y^U^Emfl_MessageList^@Before Empty^@^R^@^@^@!z^@^@!z^@^@
 <8b>F×U^_<8c>^Y^U^Emfl_MessageList^@^@^]^@^@^@!z^@^@!z^@^@
 <8b>F×U^_ <8c>^Y^U^Emfl_MessageList^@After Empty^@7^@^@^@^@^E^@^@^Z^E^@^@

这是由结构中的 logger.h 所以我觉得这是亚行的一个问题。拉源$ C ​​$ C 从这里:(貌似不少无证命令存在的)

That gets decoded by struct found in logger.h So I think this is a problem in adb. pull the source code from here: (looks like quite a few of undocumented commands there)

这是主要的功能

static int logcat(TransportType transport, const char* serial, int argc, const char** argv) {
    char* log_tags = getenv("ANDROID_LOG_TAGS");
    std::string quoted = escape_arg(log_tags == nullptr ? "" : log_tags);

    std::string cmd = "shell:export ANDROID_LOG_TAGS=\"" + quoted + "\"; exec logcat";

    if (!strcmp(argv[0], "longcat")) {
        cmd += " -v long";
    }

    --argc;
    ++argv;
    while (argc-- > 0) {
        cmd += " " + escape_arg(*argv++);
    }

    return send_shell_command(transport, serial, cmd);
}

在那里寻找我看到所有的logcat确实基本上是这样的:

Looking in there I see that all logcat does is basically this:

adb shell
> exec logcat

所以,我认为,问题的根源是logcat的本身。 Logcat.cpp调入 log_read.c

根据我快速地阅读过的东西是什么,我认为正在发生的事情是消息不正确终止。空消息没有出现,直到另一个消息被追加的第一条消息超支并显示第二条消息,因为它具有合适的终端。

Based on my quick read through things what I think is happening is the message is not terminated properly. The empty message does not show up until another message is appended and the first message overruns and shows the second message because it has the appropriate termination.

这篇关于Android的logcat的非常奇怪的现象越来越空字符串时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆