Rather strange log behavior

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();
    }
}

      

I expect this to generate 6 log messages (3 of onCreate()

, 3 of 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

      

As you can see, lines with the "SMS" tag do not pass. This is not the case as far as I can documentarily say. The question is why?

EDIT: More details on the answer.

A fairly good answer is given below by Matthew Burke. In short, based on the source code for logd_write.c

, it seems that:

  • Log

    requests with the following tags are automatically redirected to the log radio

    :
    • HTC_RIL

    • tags starting with RIL

    • AT

    • GSM

    • STK

    • CDMA

    • PHONE

    • SMS

  • No requests Log

    redirected to the log events

    (or log system

    , see also http://elinux.org/Android_Logging_System )
  • All other requests Log

    go to the log main

    , which is usually monitored.
+3


source to share


2 answers


I had to read the documentation for logcat

before starting searching through the source. According to the documentation logcat

:

The Android logging system supports multiple circular buffers for log messages, and not all log messages are sent to a circular buffer by default.

Tagged messages are SMS

sent to the radio buffer rather than the main buffer. Therefore, you will not see them unless you are done with it. If you run the command:

adb logcat -b radio

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


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



The methods in the class Log

are all wrappers around println_native

, which is a JNI method.
println_native

performs some validation on its parameters and then calls __android_log_buf_write

.

Now this last method compares the tag parameter (from the original call Log.d

) from multiple hardcoded strings (with the SMS tag being one of those lists) and if it finds a match, it ends up writing the log message to another file!

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

The relevant source can be read at

These are not official links and may disappear at some point. I'll try and hunt down the official links and edit this later in the evening.

+4


source


EDIT . Ignore this, I seem to completely disagree with this .

So I thought this was interesting, and after digging through the source I found out about Log.isLoggable()

:

Checks if the log for the specified tag is logged at the specified level. By default, any tag is set to INFO. This means that any level above and including INFO will be registered. Before making any calls to the logging method, you should check to see if your tag should be logged. You can change the default level to set the system property: 'setprop log.tag. 'Where level is VERBOSE, DEBUG, INFO, WARN, ERROR, ASSERT, or SUPPRESS. SUPPRESS will disable all entries for your tag. You can also create a local.prop file that contains the following: 'log.tag. = 'and put this in /data/local.prop.

Parameters
tag The tag to be checked. Level level Check level.

Returns
Whether or not it is allowed to register.

Apparently some tags are not allowed at certain log levels that appear to be defined in /data/local.prop

, but there must be some system level properties file that I haven't found yet. You can check this using something like this:

boolean isLoggableV = Log.isLoggable("SMS", Log.VERBOSE);
boolean isLoggableD = Log.isLoggable("SMS", Log.DEBUG);
boolean isLoggableI = Log.isLoggable("SMS", Log.INFO);
boolean isLoggableW = Log.isLoggable("SMS", Log.WARN);
boolean isLoggableE = Log.isLoggable("SMS", Log.ERROR);
boolean isLoggableA = Log.isLoggable("SMS", Log.ASSERT);

Log.v("LogTest", String.format("Verbose: %b Debug: %b Info: %b Warn: %b Error: %b Assert: %b", isLoggableV, isLoggableD, isLoggableI, isLoggableW, isLoggableE, isLoggableA));

      



Which returned the following for me:

Verbose: false Debug: false Info: true Warn: true Error: true Assert: true

      

So, you can log the tag SMS

at the log level INFO

and above, but not VERBOSE

or DEBUG

.

I have to assume this means that apps cannot accidentally log personal information, but that seems like a pretty crude way to do it.

0


source







All Articles