admin
2024-06-25 55240ee74a7d6e346b001d6e90b0762a7f456c10
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * Copyright (C) 2014 Google Inc.
 *
 * 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 com.taoke.autopay.android.utils.accessibility.internal;
 
import android.util.Log;
 
import java.util.IllegalFormatException;
 
/**
 * Handles logging formatted strings.
 */
public class LogUtils {
    private static String TAG = "LogUtils";
 
    /**
     * The minimum log level that will be printed to the console. Set this to
     * {@link Log#ERROR} for release or {@link Log#VERBOSE} for debugging.
     */
    private static int LOG_LEVEL = Log.ERROR;
 
    /**
     * Logs a formatted string to the console using the source object's name as
     * the log tag. If the source object is null, the default tag (see
     * {@link LogUtils#TAG} is used.
     * <p>
     * Example usage: <br>
     * <code>
     * LogUtils.log(this, Log.ERROR, "Invalid value: %d", value);
     * </code>
     *
     * @param source   The object that generated the log event.
     * @param priority The log entry priority, see
     *                 {@link Log#println(int, String, String)}.
     * @param format   A format string, see
     *                 {@link String#format(String, Object...)}.
     * @param args     String formatter arguments.
     */
    public static void log(Object source, int priority, String format, Object... args) {
        if (priority < LOG_LEVEL) {
            return;
        }
 
        final String sourceClass;
 
        if (source == null) {
            sourceClass = TAG;
        } else if (source instanceof Class<?>) {
            sourceClass = ((Class<?>) source).getSimpleName();
        } else {
            sourceClass = source.getClass().getSimpleName();
        }
 
        try {
            Log.println(priority, sourceClass, String.format(format, args));
        } catch (IllegalFormatException e) {
            Log.e(TAG, "Bad formatting string: \"" + format + "\"", e);
        }
    }
 
    /**
     * Logs a formatted string to the console using the default tag (see
     * {@link LogUtils#TAG}.
     *
     * @param priority The log entry priority, see
     *                 {@link Log#println(int, String, String)}.
     * @param format   A format string, see
     *                 {@link String#format(String, Object...)}.
     * @param args     String formatter arguments.
     */
    public static void log(int priority, String format, Object... args) {
        log(null, priority, format, args);
    }
 
    /**
     * Sets the log display level.
     *
     * @param logLevel The minimum log level that will be printed to the
     *                 console.
     */
    public static void setLogLevel(int logLevel) {
        LOG_LEVEL = logLevel;
    }
}