日志相当古怪的行为古怪、行为、日志

2023-09-05 08:49:46 作者:别惊动我体内的学霸

我写了一个很简单的Andr​​oid活动:

I wrote a very simple Android Activity:

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Log.d("TAG", "onCreate() Log call 1");
        Log.d("SMS", "onCreate() Log call 2");
        Log.d("TEST", "onCreate() Log call 3");

        finish();
    }

    @Override
    protected void onDestroy() {
        Log.d("TAG", "onDestroy() Log call 1");
        Log.d("SMS", "onDestroy() Log call 2");
        Log.d("TEST", "onDestroy() Log call 3");

        super.onDestroy();
    }
}

我希望它可以产生6日志消息(3从的onCreate(),3名来自的onDestroy() )。这里是logcat的:

I would expect this to generate 6 log messages (3 from onCreate(), 3 from onDestroy()). Here is the logcat:

04-14 17:31:58.363: D/TAG(18084): onCreate() Log call 1
04-14 17:31:58.363: D/TEST(18084): onCreate() Log call 3
04-14 17:31:59.905: D/TAG(18084): onDestroy() Log call 1
04-14 17:31:59.905: D/TEST(18084): onDestroy() Log call 3

如可以看到的,与标签SMS的线不通过。这不,据我可以告诉一个记录的事情。现在的问题是,为什么?

As can be seen, the lines with the tag "SMS" don't get through. This is not, as far as I can tell a documented thing. The question is, why?

编辑:更多细节上的答案

More details on the answer.

一个比较好的答案由马修·伯克如下。总之,源$ C ​​$ C的基础 logd_write.c 上,似乎是:

A rather good answer is given below by Matthew Burke. In short, on the basis of the source code for logd_write.c, it seems that:

用下面的标记 登录请求被自动重定向到无线日志: HTC_RIL 开头 RIL 标记 GSM STK CDMA 电话 短信 Log requests with the following tags are automatically redirected to the radio log: HTC_RIL tags starting with RIL AT GSM STK CDMA PHONE SMS

推荐答案

我应该读的logcat 的说明文件之前,我开始通过源打猎。据的logcat 的文档:

I should have read the documentation for logcat before I started hunting through source. According to logcat's documentation:

而Android测井系统保持多个圆孔缓冲器日志消息,并且不是所有的日志消息被发送到默认循环缓冲器。

The Android logging system keeps multiple circular buffers for log messages, and not all of the log messages are sent to the default circular buffer.

短信标签消息发送到无线缓冲区,而不是主缓冲区。因此,你不会看到它们,除非你走出自己的方式来做到这一点。如果您运行命令:

Messages with a tag of SMS are sent to the radio buffer, not the main buffer. Hence you won't see them unless you go out of your way to do so. If you run the command:

亚行logcat -b广播

您应该看到丢失的日志信息。以上信息可以在 https://developer.android.com/tool​​s/找到调试/调试-log.html 。

you should see your missing log messages. The above information can be found in https://developer.android.com/tools/debugging/debugging-log.html.

现在,对于那些你感兴趣的code洞穴探险,下面是我原来的答复:

Now, for those of you interested in code spelunking, below is my original answer:

登录类中的方法是围绕 println_native 所有包装这是一个JNI方法。 println_native 执行其参数一些验证,然后调用 __ android_log_buf_write

The methods in the Log class are all wrappers around println_native which is a JNI method. println_native performs some validation of its parameters and then calls __android_log_buf_write.

现在后一种方法的标签参数(从原来的 Log.d 通话)对几种硬codeD字符串(相比之下,标签的短信的是这个列表中的一个),如果找到匹配,缠写日志消息到不同的文件!

Now this latter method compares the tag parameter (from the original Log.d call) against several hard-coded strings (with the tag SMS being one of this list) and if it finds a match, winds up writing the log message to a different file!

顺便说一句,这得到重新路由等标签是GSM,STK,电话,CDMA,和其他几个人。

By the way, other tags that get rerouted are GSM, STK, PHONE, CDMA, and a few others.

相关源代码可以读

http://www.java2s.com/Open-Source/Android/android-core/platform-frameworks-base/android/util/Log.java.htm

https://pdroid.google$c$c.com/svn/android-2.3.4_r1/trunk/frameworks/base/core/jni/android_util_Log.cpp

的https://in-the-box.google$c$c.com/svn-history/r4/trunk/InTheBoxSim/liblog/logd_write.c

HTTP://www.takatan .NET / LXR /源/驱动器/分期/安卓/ logger.h#L33

这些都不是正式的联系,并可能会消失在某个时候。我会试着追查官方联系,并编辑这个今晚稍后。

These aren't the official links and may disappear at some point. I'll try and track down the official links and edit this later this evening.