Home » Android » logging – Log.d() or Log.e() in android prints unwanted extra texts

logging – Log.d() or Log.e() in android prints unwanted extra texts

Posted by: admin May 14, 2020 Leave a comment

Questions:

look at the image to get more ideaWhen I simply log a message in android app, Android Monitor print too much extra unwanted garbage text like:
Code:

Log.d(TAG, "From: " + "34369257099");
Log.d(TAG, "Message Notification Body: " + "Hello");

Output in android monitor:

10-01 14:15:33.262 18193-23771/com.xxxxx.xxxxxx D/MyFirebaseMsgService: From: 34369257099
10-01 14:15:33.262 18193-23771/com.xxxxx.xxxxxx D/MyFirebaseMsgService: Message Notification Body: Hello

[ 10-01 14:15:33.490 19060:19060 E/         ]
[adb] handle_packet() t->online(1) p->msg.arg0(9871) p->msg.arg1(0) OPEN


[ 10-01 14:15:33.490 19060:19060 E/         ]
[adb] handle the adb command, and the command = adb shell:cat /proc/net/xt_qtaguid/stats | grep 10206

[ 10-01 14:15:33.527 19060:19060 E/         ]
[adb] cuurent command is A_CLSE 


[ 10-01 14:15:33.686 19060:19060 E/         ]
[adb] handle_packet() t->online(1) p->msg.arg0(9872) p->msg.arg1(0) OPEN


[ 10-01 14:15:33.686 19060:19060 E/         ]
[adb] handle the adb command, and the command = adb shell:cat /proc/18193/stat

[ 10-01 14:15:33.701 19060:19060 E/         ]
[adb] cuurent command is A_CLSE 


[ 10-01 14:15:33.723 19060:19060 E/         ]
[adb] handle_packet() t->online(1) p->msg.arg0(9873) p->msg.arg1(0) OPEN


[ 10-01 14:15:33.723 19060:19060 E/         ]
[adb] handle the adb command, and the command = adb shell:cat /proc/stat

[ 10-01 14:15:33.740 19060:19060 E/         ]
[adb] cuurent command is A_CLSE 


[ 10-01 14:15:34.051 19060:19060 E/         ]
[adb] handle_packet() t->online(1) p->msg.arg0(9874) p->msg.arg1(0) OPEN


[ 10-01 14:15:34.051 19060:19060 E/         ]
[adb] handle the adb command, and the command = adb shell:cat /proc/net/xt_qtaguid/stats | grep 10206

[ 10-01 14:15:34.086 19060:19060 E/         ]
[adb] cuurent command is A_CLSE 


[ 10-01 14:15:34.258 19060:19060 E/         ]
[adb] handle_packet() t->online(1) p->msg.arg0(9875) p->msg.arg1(0) OPEN


[ 10-01 14:15:34.258 19060:19060 E/         ]
[adb] handle the adb command, and the command = adb shell:cat /proc/18193/stat

[ 10-01 14:15:34.274 19060:19060 E/         ]
[adb] cuurent command is A_CLSE 


[ 10-01 14:15:34.294 19060:19060 E/         ]
[adb] handle_packet() t->online(1) p->msg.arg0(9876) p->msg.arg1(0) OPEN


[ 10-01 14:15:34.294 19060:19060 E/         ]
[adb] handle the adb command, and the command = adb shell:cat /proc/stat

[ 10-01 14:15:34.315 19060:19060 E/         ]
[adb] cuurent command is A_CLSE 


[ 10-01 14:15:34.613 19060:19060 E/         ]
[adb] handle_packet() t->online(1) p->msg.arg0(9877) p->msg.arg1(0) OPEN


[ 10-01 14:15:34.613 19060:19060 E/         ]
[adb] handle the adb command, and the command = adb shell:cat /proc/net/xt_qtaguid/stats | grep 10206

[ 10-01 14:15:34.648 19060:19060 E/         ]
[adb] cuurent command is A_CLSE 


[ 10-01 14:15:34.831 19060:19060 E/         ]
[adb] handle_packet() t->online(1) p->msg.arg0(9878) p->msg.arg1(0) OPEN


[ 10-01 14:15:34.831 19060:19060 E/         ]
[adb] handle the adb command, and the command = adb shell:cat /proc/18193/stat

[ 10-01 14:15:34.849 19060:19060 E/         ]
[adb] cuurent command is A_CLSE 


[ 10-01 14:15:34.867 19060:19060 E/         ]
[adb] handle_packet() t->online(1) p->msg.arg0(9879) p->msg.arg1(0) OPEN


[ 10-01 14:15:34.867 19060:19060 E/         ]
[adb] handle the adb command, and the command = adb shell:cat /proc/stat

[ 10-01 14:15:34.885 19060:19060 E/         ]
[adb] cuurent command is A_CLSE 


[ 10-01 14:15:35.176 19060:19060 E/         ]
[adb] handle_packet() t->online(1) p->msg.arg0(9880) p->msg.arg1(0) OPEN


[ 10-01 14:15:35.176 19060:19060 E/         ]
[adb] handle the adb command, and the command = adb shell:cat /proc/net/xt_qtaguid/stats | grep 10206

[ 10-01 14:15:35.210 19060:19060 E/         ]
[adb] cuurent command is A_CLSE 


[ 10-01 14:15:35.404 19060:19060 E/         ]
[adb] handle_packet() t->online(1) p->msg.arg0(9881) p->msg.arg1(0) OPEN


[ 10-01 14:15:35.404 19060:19060 E/         ]
[adb] handle the adb command, and the command = adb shell:cat /proc/18193/stat

[ 10-01 14:15:35.421 19060:19060 E/         ]
[adb] cuurent command is A_CLSE 


[ 10-01 14:15:35.439 19060:19060 E/         ]
[adb] handle_packet() t->online(1) p->msg.arg0(9882) p->msg.arg1(0) OPEN


[ 10-01 14:15:35.439 19060:19060 E/         ]
[adb] handle the adb command, and the command = adb shell:cat /proc/stat

[ 10-01 14:15:35.457 19060:19060 E/         ]
[adb] cuurent command is A_CLSE 


[ 10-01 14:15:35.738 19060:19060 E/         ]
[adb] handle_packet() t->online(1) p->msg.arg0(9883) p->msg.arg1(0) OPEN


[ 10-01 14:15:35.738 19060:19060 E/         ]
[adb] handle the adb command, and the command = adb shell:cat /proc/net/xt_qtaguid/stats | grep 10206

[ 10-01 14:15:35.764 19060:19060 E/         ]
[adb] cuurent command is A_CLSE 


[ 10-01 14:15:35.974 19060:19060 E/         ]
[adb] handle_packet() t->online(1) p->msg.arg0(9884) p->msg.arg1(0) OPEN


[ 10-01 14:15:35.974 19060:19060 E/         ]
[adb] handle the adb command, and the command = adb shell:cat /proc/18193/stat

[ 10-01 14:15:35.990 19060:19060 E/         ]
[adb] cuurent command is A_CLSE 


[ 10-01 14:15:36.009 19060:19060 E/         ]
[adb] handle_packet() t->online(1) p->msg.arg0(9885) p->msg.arg1(0) OPEN


[ 10-01 14:15:36.009 19060:19060 E/         ]
[adb] handle the adb command, and the command = adb shell:cat /proc/stat

Can You please help me solve this? I mean why does this extra text gets printed? and how do I get rid of this?
I have used filter to display only package related logs and tried filtering TAG wise too. But see in image attached that still garbage text gets printed in some Logs.

Thanks in Advance

How to&Answers:

Since the unwanted lines all seem to have ‘[‘ in them, we should be able to create a filter that excludes those lines & get what you need (you won’t be able to use that character in any of your log statements).

Create a filter using ^[^\[]+$ as the Log Message (& make sure Regex is selected). You’ll also have to set either the Log Tag or Package Name or you get everything from other apps that doesn’t include ‘[‘.

Thanks to here for the help with the regex.

screenshot of logcat Filter editor

Answer:

See the image properly to the top right corner, We have something like a basic filter. Using Show Only Selected Application will let you only see what Belongs to your app. you Can Use Edit Filter Configuration to use more complex Filters.

Answer:

Do you use ndk librairies ?

Those logs kind look like native code output.

https://android.googlesource.com/platform/system/core/+/android-4.4_r1/adb/adb.c have some commands that output lines like you have :

D("handle_packet() %c%c%c%c\n", ((char*) (&(p->msg.command)))[0],
            ((char*) (&(p->msg.command)))[1],
            ((char*) (&(p->msg.command)))[2],
            ((char*) (&(p->msg.command)))[3]);

I’m afraid that you wont be able to controll those outputs, excepting in excluding or rewriting native code that you embed in your project. If you don’t embed specific native libraries, this is probably from native core sources of os device.

Answer:

There are two ways to do this

  1. First download cygwin terminal and run command adb logcat | grep appname

    here app name is your application name which is used in package name. Note this command only will run in cygwin.
  2. Filtering log output
    The tag of a log message is a short string indicating the system component from which the message originates (for example, “View” for the view system).
    The priority is one of the following character values, ordered from lowest to highest priority:
    V: Verbose (lowest priority)
    D: Debug
    I: Info
    W: Warning
    E: Error
    F: Fatal
    S: Silent (highest priority, on which nothing is ever printed)
    You can obtain a list of tags used in the system, with priorities, by running logcat and observing the first two columns of each message, given as /.

The following is an example of brief logcat output obtained with the logcat -v brief output command. It shows that the message relates to priority level “I” and tag “ActivityManager”:

I/ActivityManager(  585): Starting activity: Intent { action=android.intent.action...}

To reduce the log output to a manageable level, you can restrict log output using filter expressions. Filter expressions let you indicate to the system the tags-priority combinations that you are interested in — the system suppresses other messages for the specified tags.

A filter expression follows this format tag:priority …, where tag indicates the tag of interest and priority indicates the minimum level of priority to report for that tag. Messages for that tag at or above the specified priority are written to the log. You can supply any number of tag:priority specifications in a single filter expression. The series of specifications is whitespace-delimited.

Here’s an example of a filter expression that suppresses all log messages except those with the tag “ActivityManager”, at priority “Info” or above, and all log messages with tag “MyApp”, with priority “Debug” or above:

adb logcat ActivityManager:I MyApp:D *:S

The final element in the above expression, *:S, sets the priority level for all tags to “silent”, thus ensuring only log messages with “ActivityManager” and “MyApp” are displayed. Using *:S is an excellent way to ensure that log output is restricted to the filters that you have explicitly specified — it lets your filters serve as a “whitelist” for log output.

The following filter expression displays all log messages with priority level “warning” and higher, on all tags:

 adb logcat *:W

If you’re running logcat from your development computer (versus running it on a remote adb shell), you can also set a default filter expression by exporting a value for the environment variable ANDROID_LOG_TAGS:

export ANDROID_LOG_TAGS="ActivityManager:I MyApp:D *:S"

Note that ANDROID_LOG_TAGS filter is not exported to the emulator/device instance, if you are running logcat from a remote shell or using adb shell logcat.

Answer:

They are logs from another process. You can’t prevent them from happening, so you have to filter the log output to show only what’s interesting to you.

Answer:

Just a guess: you are using an alternative Log class that adds more output.
To check this, change Log.d() calls to android.util.Log.d() calls.