Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit afd54674 authored by Tony Mak's avatar Tony Mak
Browse files

Use isLoggable so that we can enable full logging easily

Also, change to use android.util.Log rather than Slog, which should
be used by system service only.

Test: Try out adb shell setprop log.tag.androidtc and observe verbose
      logging.

Change-Id: Ie86c6b3f8bd39957f041ffe3a10abb7584f96f83
parent 41c8f388
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ import java.util.UUID;
public final class GenerateLinksLogger {

    private static final String LOG_TAG = "GenerateLinksLogger";
    private static final boolean DEBUG_LOG_ENABLED = false;
    private static final String ZERO = "0";

    private final MetricsLogger mMetricsLogger;
@@ -128,8 +127,9 @@ public final class GenerateLinksLogger {
    }

    private static void debugLog(LogMaker log) {
        if (!DEBUG_LOG_ENABLED) return;

        if (!Log.ENABLE_FULL_LOGGING) {
            return;
        }
        final String callId = Objects.toString(
                log.getTaggedData(MetricsEvent.FIELD_LINKIFY_CALL_ID), "");
        final String entityType = Objects.toString(
@@ -143,7 +143,7 @@ public final class GenerateLinksLogger {
        final int latencyMs = Integer.parseInt(
                Objects.toString(log.getTaggedData(MetricsEvent.FIELD_LINKIFY_LATENCY), ZERO));

        Log.d(LOG_TAG,
        Log.v(LOG_TAG,
                String.format(Locale.US, "%s:%s %d links (%d/%d chars) %dms %s", callId, entityType,
                        numLinks, linkLength, textLength, latencyMs, log.getPackageName()));
    }
+18 −8
Original line number Diff line number Diff line
@@ -16,10 +16,12 @@

package android.view.textclassifier;

import android.util.Slog;

/**
 * Logging for android.view.textclassifier package.
 * <p>
 * To enable full log:
 * 1. adb shell setprop log.tag.androidtc VERBOSE
 * 2. adb shell stop && adb shell start
 */
final class Log {

@@ -27,24 +29,32 @@ final class Log {
     * true: Enables full logging.
     * false: Limits logging to debug level.
     */
    private static final boolean ENABLE_FULL_LOGGING = false;
    static final boolean ENABLE_FULL_LOGGING =
            android.util.Log.isLoggable(TextClassifier.DEFAULT_LOG_TAG, android.util.Log.VERBOSE);

    private Log() {
    }

    private Log() {}
    public static void v(String tag, String msg) {
        if (ENABLE_FULL_LOGGING) {
            android.util.Log.v(tag, msg);
        }
    }

    public static void d(String tag, String msg) {
        Slog.d(tag, msg);
        android.util.Log.d(tag, msg);
    }

    public static void w(String tag, String msg) {
        Slog.w(tag, msg);
        android.util.Log.w(tag, msg);
    }

    public static void e(String tag, String msg, Throwable tr) {
        if (ENABLE_FULL_LOGGING) {
            Slog.e(tag, msg, tr);
            android.util.Log.e(tag, msg, tr);
        } else {
            final String trString = (tr != null) ? tr.getClass().getSimpleName() : "??";
            Slog.d(tag, String.format("%s (%s)", msg, trString));
            android.util.Log.d(tag, String.format("%s (%s)", msg, trString));
        }
    }
}
+4 −4
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ import java.util.StringJoiner;
public final class SelectionSessionLogger {

    private static final String LOG_TAG = "SelectionSessionLogger";
    private static final boolean DEBUG_LOG_ENABLED = false;
    static final String CLASSIFIER_ID = "androidtc";

    private static final int START_EVENT_DELTA = MetricsEvent.FIELD_SELECTION_SINCE_START;
@@ -195,8 +194,9 @@ public final class SelectionSessionLogger {
    }

    private static void debugLog(LogMaker log) {
        if (!DEBUG_LOG_ENABLED) return;

        if (!Log.ENABLE_FULL_LOGGING) {
            return;
        }
        final String widgetType = Objects.toString(log.getTaggedData(WIDGET_TYPE), UNKNOWN);
        final String widgetVersion = Objects.toString(log.getTaggedData(WIDGET_VERSION), "");
        final String widget = widgetVersion.isEmpty()
@@ -221,7 +221,7 @@ public final class SelectionSessionLogger {
        final int eventEnd = Integer.parseInt(
                Objects.toString(log.getTaggedData(EVENT_END), ZERO));

        Log.d(LOG_TAG,
        Log.v(LOG_TAG,
                String.format(Locale.US, "%2d: %s/%s/%s, range=%d,%d - smart_range=%d,%d (%s/%s)",
                        index, type, subType, entity, eventStart, eventEnd, smartStart, smartEnd,
                        widget, model));
+1 −4
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import com.android.internal.util.Preconditions;
@WorkerThread
final class TextClassificationSession implements TextClassifier {

    /* package */ static final boolean DEBUG_LOG_ENABLED = true;
    private static final String LOG_TAG = "TextClassificationSession";

    private final TextClassifier mDelegate;
@@ -133,9 +132,7 @@ final class TextClassificationSession implements TextClassifier {

            if (event.getEventType() != SelectionEvent.EVENT_SELECTION_STARTED
                    && mStartEvent == null) {
                if (DEBUG_LOG_ENABLED) {
                Log.d(LOG_TAG, "Selection session not yet started. Ignoring event");
                }
                return false;
            }

+2 −3
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ import com.android.internal.util.Preconditions;
public final class TextClassifierEventTronLogger {

    private static final String TAG = "TCEventTronLogger";
    private static final boolean DEBUG_LOG_ENABLED = false;

    private final MetricsLogger mMetricsLogger;

@@ -125,7 +124,7 @@ public final class TextClassifierEventTronLogger {
    }

    private void debugLog(LogMaker log) {
        if (!DEBUG_LOG_ENABLED) {
        if (!Log.ENABLE_FULL_LOGGING) {
            return;
        }
        final String id = String.valueOf(log.getTaggedData(FIELD_SELECTION_SESSION_ID));
@@ -147,6 +146,6 @@ public final class TextClassifierEventTronLogger {
        builder.append(", model=").append(model);
        builder.append(", entityType=").append(entityType);

        Log.d(TAG, builder.toString());
        Log.v(TAG, builder.toString());
    }
}