Log not working (or seems to drop some lines)

给你一囗甜甜゛ 提交于 2020-01-05 04:27:05

问题


EDIT: A more honed version of this question, with a good answer, is at: Rather odd behaviour of Log

EDIT: The (bizarre) solution is reported as an answer below.

I have a service as part of an application which is running reasonably well, although there is an unusual bit of behaviour which I am trying to understand. To do this, I have been putting Log.d statement in various methods in classes to report state information at various points. All of these seem to be working (ie reporting the information) except those in the Service class. I know that the service is started because (a) it does something and (b) the threads it instantiates are issuing Log.d messages. However, even right at the start:

@Override
public void onCreate() {
    super.onCreate();
    Log.d("SMS", "onCreate()");
    onCreateReal();
}

This log message never appears. What might I be doing wrong?

The manifest is as follows:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.stuff.myapp"
android:versionCode="1111111"
android:versionName="0.1" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity
        android:name="com.stuff.myapp.Core"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <service android:name="MyService"></service>

    <receiver android:name="com.stuff.myapp.WidgetInitiator">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
        </intent-filter>
        <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_information"/>
    </receiver>

    <activity android:name="com.stuff.myapp.ConfigWidgetActivity"
         android:theme="@android:style/Theme.Translucent">
    </activity>
</application>

[EDIT: another observation] As part of the app, I am calling a BroadcastReceiver class every 2 minutes (in testing). The class is stand alone (ie not inside any of the other classes). It does a Log.d every time it is called by AlarmManager. But only some of he Log calls make it to logcat. Again, suggestions welcome for what might be going on here.

[EDIT: I have corrected the above because the Threads it instantiates report Log calls correctly, but classes it instantiates don't.]


回答1:


Having done quite a lot of work resolving the underlying issue (see Service being re-Created by AlarmManager), I still had this problem. The service still wasn't logging. For no reason I can explain, changing TAG from "SMS" to "SMservice" made it work. I can offer no good explanation other than it seemed to solve the problem.

And, to save you asking, if I change TAG back to "SMS" the messages disappear again.




回答2:


You should use "tag:SMS" as filter in logcat.



来源:https://stackoverflow.com/questions/15409796/log-not-working-or-seems-to-drop-some-lines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!