summaryrefslogtreecommitdiff
path: root/sdksandbox/framework/java/android/app/sdksandbox/LogUtil.java
blob: 2e414bc7c6d403c551a3a4f0bda0708f553ec5db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.app.sdksandbox;

import android.util.Log;

/**
 * Utility class for logging behind {@link Log#isLoggable} check.
 *
 * <p>Logging can be enabled by running {@code adb shell setprop persist.log.tag.SDK_SANDBOX DEBUG}
 * or individual tag used while logging with {@link LogUtil}.
 *
 * @hide
 */
public class LogUtil {

    public static final String GUARD_TAG = "SDK_SANDBOX";

    /** Log the message as VERBOSE. Return The number of bytes written. */
    public static int v(String tag, String msg) {
        if (Log.isLoggable(GUARD_TAG, Log.VERBOSE) || Log.isLoggable(tag, Log.VERBOSE)) {
            return Log.v(tag, msg);
        }
        return 0;
    }

    /** Log the message as DEBUG. Return The number of bytes written. */
    public static int d(String tag, String msg) {
        if (Log.isLoggable(GUARD_TAG, Log.DEBUG) || Log.isLoggable(tag, Log.DEBUG)) {
            return Log.d(tag, msg);
        }
        return 0;
    }
}