How can I disable Android's internal logging f

2020-06-06 04:53发布

Intro

I'm developing an application for android and it seems that there're some persistent logging enabled in the mighty system, see some examples below. I'm debugging from Eclipse on my Galaxy S4 device (4.2.2).

Here's a list of types of log messages I see in the LogCat view:

  • I/System.out: it's the debuggers output, signs the start of the app, useful
  • D/dalvikvm: GC_FOR_ALLOC, GC_CONCURRENT are useful to see I produced too much garbage with my code
  • D/AbsListView, I/endeffect: every time a ListView is created, i.e. mostly when I navigate between activities
  • I/CustomFrequencyManager, D/GestureDetector: every time I touch the screen
  • W/IInputConnectionWrapper: don't know, but definitely not my fault, i.e. spam
  • others: don't mind, as they're mostly errors

Question

How can I disable specific log messages which are not produced by my code? To get rid of the listview creation logs, I've already tried:

  • adb shell setprop log.tag.AbsListView INFO from Windows cmd
  • System.setProperties("log.tag.AbsListView", "INFO") in Application.onCreate

I'm looking for a solution which

  • I can embed in my app's code/configuration, so I don't have to execute it every time I restart the phone (as it would be the case with adb setprop).
  • is not setting the log level to WARN in the LogCat view, because that would mean I'm stuck with about WARN, ERROR and FATAL for my own application (which, you must admit is not the optimal way communicating debug messages; plus it would hide important stuff like GC!)

And the log

10-26 18:45:36.387: W/ActivityThread(10956): Application com.example.android.apis is waiting for the debugger on port 8100...
10-26 18:45:36.437: I/System.out(10956): Sending WAIT chunk
10-26 18:45:36.447: I/dalvikvm(10956): Debugger is active
10-26 18:45:36.638: I/System.out(10956): Debugger has connected
10-26 18:45:36.638: I/System.out(10956): waiting for debugger to settle...
10-26 18:45:36.838: I/System.out(10956): waiting for debugger to settle...
10-26 18:45:37.038: I/System.out(10956): waiting for debugger to settle...
10-26 18:45:37.839: I/System.out(10956): debugger has settled (1325)
10-26 18:45:38.610: E/MoreInfoHPW_ViewGroup(10956): Parent view is not a TextView
10-26 18:45:38.680: D/dalvikvm(10956): GC_FOR_ALLOC freed 767K, 9% free 17300K/18984K, paused 17ms, total 20ms
10-26 18:45:38.690: I/dalvikvm-heap(10956): Grow heap (frag case) to 20.036MB for 2359312-byte allocation
10-26 18:45:38.700: D/dalvikvm(10956): GC_FOR_ALLOC freed 3K, 8% free 19600K/21292K, paused 13ms, total 13ms
10-26 18:45:38.720: D/dalvikvm(10956): GC_CONCURRENT freed <1K, 8% free 19601K/21292K, paused 3ms+5ms, total 17ms
10-26 18:45:38.760: D/AbsListView(10956): Get MotionRecognitionManager
10-26 18:45:38.770: D/AbsListView(10956): onVisibilityChanged() is called, visibility : 4
10-26 18:45:38.770: D/AbsListView(10956): unregisterIRListener() is called 
10-26 18:45:38.890: D/AbsListView(10956): onVisibilityChanged() is called, visibility : 0
10-26 18:45:38.890: D/AbsListView(10956): unregisterIRListener() is called 
10-26 18:45:38.920: D/AbsListView(10956): unregisterIRListener() is called 
10-26 18:45:38.950: I/endeffect(10956): AbsListView.onMeasure(), getWidth()=0, getHeight()=0, this=android.widget.ListView{424124d8 VFED.VC. .F....I. 0,0-0,0 #102000a android:id/list}
10-26 18:45:38.960: D/libEGL(10956): loaded /system/lib/egl/libEGL_adreno200.so
10-26 18:45:38.960: D/libEGL(10956): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
10-26 18:45:38.970: D/libEGL(10956): loaded /system/lib/egl/libGLESv2_adreno200.so
10-26 18:45:38.970: I/Adreno200-EGL(10956): <qeglDrvAPI_eglInitialize:265>: EGL 1.4 QUALCOMM build:  (CL3579225)
10-26 18:45:38.970: I/Adreno200-EGL(10956): Build Date: 04/22/13 Mon
10-26 18:45:38.970: I/Adreno200-EGL(10956): Local Branch: adreno_sba_20130419
10-26 18:45:38.970: I/Adreno200-EGL(10956): Remote Branch: 
10-26 18:45:38.970: I/Adreno200-EGL(10956): Local Patches: 
10-26 18:45:38.970: I/Adreno200-EGL(10956): Reconstruct Branch: 
10-26 18:45:39.040: D/OpenGLRenderer(10956): Enabling debug mode 0
10-26 18:45:39.150: D/AbsListView(10956): unregisterIRListener() is called 
10-26 18:45:39.150: I/endeffect(10956): AbsListView.onLayout(), getWidth()=1080, getHeight()=1701, this=android.widget.ListView{424124d8 VFED.VC. .F....ID 0,0-1080,1701 #102000a android:id/list}
10-26 18:45:39.320: D/AbsListView(10956): unregisterIRListener() is called 
10-26 18:45:39.480: I/endeffect(10956): AbsListView.onMeasure(), getWidth()=1080, getHeight()=1701, this=android.widget.ListView{424124d8 VFED.VC. .F....I. 0,0-1080,1701 #102000a android:id/list}
10-26 18:45:39.490: D/AbsListView(10956): unregisterIRListener() is called 
10-26 18:45:39.490: I/endeffect(10956): AbsListView.onLayout(), getWidth()=1080, getHeight()=1701, this=android.widget.ListView{424124d8 VFED.VC. .F....ID 0,0-1080,1701 #102000a android:id/list}
10-26 18:45:56.757: I/CustomFrequencyManager(10956): newFrequencyRequest  - mFrequency = 1566000, mTimeoutMs = -1, mPkgName = LIST_SCROLL_BOOSTER@1
10-26 18:45:56.757: I/CustomFrequencyManager(10956): Boost Request from package = LIST_SCROLL_BOOSTER@1 frequency : 1566000type = 6
10-26 18:45:56.767: I/CustomFrequencyManager(10956): !! pkgName = LIST_SCROLL_BOOSTER@1
10-26 18:45:56.767: I/CustomFrequencyManager(10956): Request from package name pkgName = LIST_SCROLL_BOOSTER@1
10-26 18:45:56.767: I/CustomFrequencyManager(10956): mContext is Not Null  mContext.pkgName = com.example.android.apis
10-26 18:45:56.767: I/CustomFrequencyManager(10956): mToken is Null....Creating New Binder!
10-26 18:45:56.767: I/CustomFrequencyManager(10956): CPUDVFSControlRequest : doFrequencyRequest::  = 1566000 Timeout : -1
10-26 18:45:56.767: I/CustomFrequencyManager(10956): newFrequencyRequest  - mFrequency = 2, mTimeoutMs = -1, mPkgName = LIST_SCROLL_BOOSTER_CORE@2
10-26 18:45:56.767: I/CustomFrequencyManager(10956): Boost Request from package = LIST_SCROLL_BOOSTER_CORE@2 frequency : 2type = 4
10-26 18:45:56.767: I/CustomFrequencyManager(10956): !! pkgName = LIST_SCROLL_BOOSTER_CORE@2
10-26 18:45:56.767: I/CustomFrequencyManager(10956): Request from package name pkgName = LIST_SCROLL_BOOSTER_CORE@2
10-26 18:45:56.777: I/CustomFrequencyManager(10956): mContext is Not Null  mContext.pkgName = com.example.android.apis
10-26 18:45:56.777: I/CustomFrequencyManager(10956): mToken is Null....Creating New Binder!
10-26 18:45:56.777: I/CustomFrequencyManager(10956): CPUCoreControlRequest : doFrequencyRequest::  = 2 Timeout : -1
10-26 18:45:56.807: D/GestureDetector(10956): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 8 mFalseSizeCnt:0
10-26 18:45:57.908: I/CustomFrequencyManager(10956): newFrequencyRequest  - mFrequency = 1566000, mTimeoutMs = -1, mPkgName = LIST_SCROLL_BOOSTER@1
10-26 18:45:57.908: I/CustomFrequencyManager(10956): Boost Request from package = LIST_SCROLL_BOOSTER@1 frequency : 1566000type = 6
10-26 18:45:57.908: I/CustomFrequencyManager(10956): !! pkgName = LIST_SCROLL_BOOSTER@1
10-26 18:45:57.908: I/CustomFrequencyManager(10956): Request from package name pkgName = LIST_SCROLL_BOOSTER@1
10-26 18:45:57.908: I/CustomFrequencyManager(10956): mContext is Not Null  mContext.pkgName = com.example.android.apis
10-26 18:45:57.908: I/CustomFrequencyManager(10956): mToken is Null....Creating New Binder!
10-26 18:45:57.908: I/CustomFrequencyManager(10956): CPUDVFSControlRequest : doFrequencyRequest::  = 1566000 Timeout : -1
10-26 18:45:57.918: I/CustomFrequencyManager(10956): newFrequencyRequest  - mFrequency = 2, mTimeoutMs = -1, mPkgName = LIST_SCROLL_BOOSTER_CORE@2
10-26 18:45:57.918: I/CustomFrequencyManager(10956): Boost Request from package = LIST_SCROLL_BOOSTER_CORE@2 frequency : 2type = 4
10-26 18:45:57.918: I/CustomFrequencyManager(10956): !! pkgName = LIST_SCROLL_BOOSTER_CORE@2
10-26 18:45:57.918: I/CustomFrequencyManager(10956): Request from package name pkgName = LIST_SCROLL_BOOSTER_CORE@2
10-26 18:45:57.928: I/CustomFrequencyManager(10956): mContext is Not Null  mContext.pkgName = com.example.android.apis
10-26 18:45:57.928: I/CustomFrequencyManager(10956): mToken is Null....Creating New Binder!
10-26 18:45:57.928: I/CustomFrequencyManager(10956): CPUCoreControlRequest : doFrequencyRequest::  = 2 Timeout : -1
10-26 18:45:58.099: D/GestureDetector(10956): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 17 mFalseSizeCnt:0
10-26 18:46:09.209: I/CustomFrequencyManager(10956): newFrequencyRequest  - mFrequency = 1566000, mTimeoutMs = -1, mPkgName = LIST_SCROLL_BOOSTER@1
10-26 18:46:09.209: I/CustomFrequencyManager(10956): Boost Request from package = LIST_SCROLL_BOOSTER@1 frequency : 1566000type = 6
10-26 18:46:09.219: I/CustomFrequencyManager(10956): !! pkgName = LIST_SCROLL_BOOSTER@1
10-26 18:46:09.219: I/CustomFrequencyManager(10956): Request from package name pkgName = LIST_SCROLL_BOOSTER@1
10-26 18:46:09.219: I/CustomFrequencyManager(10956): mContext is Not Null  mContext.pkgName = com.example.android.apis
10-26 18:46:09.219: I/CustomFrequencyManager(10956): mToken is Null....Creating New Binder!
10-26 18:46:09.219: I/CustomFrequencyManager(10956): CPUDVFSControlRequest : doFrequencyRequest::  = 1566000 Timeout : -1
10-26 18:46:09.219: I/CustomFrequencyManager(10956): newFrequencyRequest  - mFrequency = 2, mTimeoutMs = -1, mPkgName = LIST_SCROLL_BOOSTER_CORE@2
10-26 18:46:09.229: I/CustomFrequencyManager(10956): Boost Request from package = LIST_SCROLL_BOOSTER_CORE@2 frequency : 2type = 4
10-26 18:46:09.229: I/CustomFrequencyManager(10956): !! pkgName = LIST_SCROLL_BOOSTER_CORE@2
10-26 18:46:09.229: I/CustomFrequencyManager(10956): Request from package name pkgName = LIST_SCROLL_BOOSTER_CORE@2
10-26 18:46:09.229: I/CustomFrequencyManager(10956): mContext is Not Null  mContext.pkgName = com.example.android.apis
10-26 18:46:09.229: I/CustomFrequencyManager(10956): mToken is Null....Creating New Binder!
10-26 18:46:09.229: I/CustomFrequencyManager(10956): CPUCoreControlRequest : doFrequencyRequest::  = 2 Timeout : -1
10-26 18:46:09.930: D/GestureDetector(10956): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 51 mFalseSizeCnt:0
10-26 18:46:17.347: D/GestureDetector(10956): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 9 mFalseSizeCnt:0
10-26 18:46:18.028: E/MoreInfoHPW_ViewGroup(10956): Parent view is not a TextView
10-26 18:46:18.058: D/AbsListView(10956): Get MotionRecognitionManager
10-26 18:46:18.068: D/AbsListView(10956): onVisibilityChanged() is called, visibility : 4
10-26 18:46:18.068: D/AbsListView(10956): unregisterIRListener() is called 
10-26 18:46:18.078: D/AbsListView(10956): onVisibilityChanged() is called, visibility : 0
10-26 18:46:18.078: D/AbsListView(10956): unregisterIRListener() is called 
10-26 18:46:18.078: D/AbsListView(10956): unregisterIRListener() is called 
10-26 18:46:18.098: D/AbsListView(10956): unregisterIRListener() is called 
10-26 18:46:18.128: I/endeffect(10956): AbsListView.onMeasure(), getWidth()=0, getHeight()=0, this=android.widget.ListView{427b2ca0 VFED.VC. .F....I. 0,0-0,0 #102000a android:id/list}
10-26 18:46:18.228: D/AbsListView(10956): unregisterIRListener() is called 
10-26 18:46:18.228: I/endeffect(10956): AbsListView.onLayout(), getWidth()=1080, getHeight()=1701, this=android.widget.ListView{427b2ca0 VFED.VC. .F....ID 0,0-1080,1701 #102000a android:id/list}
10-26 18:46:18.338: D/AbsListView(10956): unregisterIRListener() is called 
10-26 18:46:18.408: I/endeffect(10956): AbsListView.onMeasure(), getWidth()=1080, getHeight()=1701, this=android.widget.ListView{427b2ca0 VFED.VC. .F....I. 0,0-1080,1701 #102000a android:id/list}
10-26 18:46:18.418: D/AbsListView(10956): unregisterIRListener() is called 
10-26 18:46:18.418: I/endeffect(10956): AbsListView.onLayout(), getWidth()=1080, getHeight()=1701, this=android.widget.ListView{427b2ca0 VFED.VC. .F....ID 0,0-1080,1701 #102000a android:id/list}
10-26 18:46:18.549: W/IInputConnectionWrapper(10956): setComposingText on inactive InputConnection
10-26 18:46:18.559: D/AbsListView(10956): onVisibilityChanged() is called, visibility : 4
10-26 18:46:18.559: D/AbsListView(10956): unregisterIRListener() is called 
10-26 18:46:23.914: I/CustomFrequencyManager(10956): newFrequencyRequest  - mFrequency = 1566000, mTimeoutMs = -1, mPkgName = LIST_SCROLL_BOOSTER@3
10-26 18:46:23.914: I/CustomFrequencyManager(10956): Boost Request from package = LIST_SCROLL_BOOSTER@3 frequency : 1566000type = 6
10-26 18:46:23.914: I/CustomFrequencyManager(10956): !! pkgName = LIST_SCROLL_BOOSTER@3
10-26 18:46:23.914: I/CustomFrequencyManager(10956): Request from package name pkgName = LIST_SCROLL_BOOSTER@3
10-26 18:46:23.914: I/CustomFrequencyManager(10956): mContext is Not Null  mContext.pkgName = com.example.android.apis
10-26 18:46:23.914: I/CustomFrequencyManager(10956): mToken is Null....Creating New Binder!
10-26 18:46:23.914: I/CustomFrequencyManager(10956): CPUDVFSControlRequest : doFrequencyRequest::  = 1566000 Timeout : -1
10-26 18:46:23.924: I/CustomFrequencyManager(10956): newFrequencyRequest  - mFrequency = 2, mTimeoutMs = -1, mPkgName = LIST_SCROLL_BOOSTER_CORE@4
10-26 18:46:23.924: I/CustomFrequencyManager(10956): Boost Request from package = LIST_SCROLL_BOOSTER_CORE@4 frequency : 2type = 4
10-26 18:46:23.924: I/CustomFrequencyManager(10956): !! pkgName = LIST_SCROLL_BOOSTER_CORE@4
10-26 18:46:23.924: I/CustomFrequencyManager(10956): Request from package name pkgName = LIST_SCROLL_BOOSTER_CORE@4
10-26 18:46:23.924: I/CustomFrequencyManager(10956): mContext is Not Null  mContext.pkgName = com.example.android.apis
10-26 18:46:23.924: I/CustomFrequencyManager(10956): mToken is Null....Creating New Binder!
10-26 18:46:23.924: I/CustomFrequencyManager(10956): CPUCoreControlRequest : doFrequencyRequest::  = 2 Timeout : -1
10-26 18:46:24.835: D/GestureDetector(10956): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 61 mFalseSizeCnt:0
10-26 18:46:26.676: D/GestureDetector(10956): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 11 mFalseSizeCnt:0
10-26 18:46:27.307: E/MoreInfoHPW_ViewGroup(10956): Parent view is not a TextView
10-26 18:46:27.337: D/AbsListView(10956): Get MotionRecognitionManager
10-26 18:46:27.347: D/AbsListView(10956): onVisibilityChanged() is called, visibility : 4
10-26 18:46:27.347: D/AbsListView(10956): unregisterIRListener() is called 
10-26 18:46:27.357: D/AbsListView(10956): onVisibilityChanged() is called, visibility : 0
10-26 18:46:27.357: D/AbsListView(10956): unregisterIRListener() is called 
10-26 18:46:27.357: D/AbsListView(10956): unregisterIRListener() is called 
10-26 18:46:27.387: D/AbsListView(10956): unregisterIRListener() is called 
10-26 18:46:27.407: I/endeffect(10956): AbsListView.onMeasure(), getWidth()=0, getHeight()=0, this=android.widget.ListView{4286ddf8 VFED.VC. .F....I. 0,0-0,0 #102000a android:id/list}
10-26 18:46:27.517: D/AbsListView(10956): unregisterIRListener() is called 
10-26 18:46:27.517: I/endeffect(10956): AbsListView.onLayout(), getWidth()=1080, getHeight()=1701, this=android.widget.ListView{4286ddf8 VFED.VC. .F....ID 0,0-1080,1701 #102000a android:id/list}
10-26 18:46:27.627: D/AbsListView(10956): unregisterIRListener() is called 
10-26 18:46:27.727: I/endeffect(10956): AbsListView.onMeasure(), getWidth()=1080, getHeight()=1701, this=android.widget.ListView{4286ddf8 VFED.VC. .F....I. 0,0-1080,1701 #102000a android:id/list}
10-26 18:46:27.738: D/AbsListView(10956): unregisterIRListener() is called 
10-26 18:46:27.738: I/endeffect(10956): AbsListView.onLayout(), getWidth()=1080, getHeight()=1701, this=android.widget.ListView{4286ddf8 VFED.VC. .F....ID 0,0-1080,1701 #102000a android:id/list}
10-26 18:46:27.808: W/IInputConnectionWrapper(10956): setComposingText on inactive InputConnection
10-26 18:46:27.818: D/AbsListView(10956): onVisibilityChanged() is called, visibility : 4
10-26 18:46:27.818: D/AbsListView(10956): unregisterIRListener() is called 

Here's a fun fact: all of the above was generated by the Android ApiDemos application started in Debug mode and going to Views/Lists and back.

1条回答
孤傲高冷的网名
2楼-- · 2020-06-06 05:38

How can I disable specific log messages which are not produced by my code?

if you are using Eclipse you can only show logs produced by your application by defining a filter. On the bottom left of the LogCat window click the plus icon to create a new filter. "By Application name" field needs the following format: com.yourpackage.yourapp. After saving this filter you can just click it to see only message related to your app

查看更多
登录 后发表回答