این وبسایت یک نسخه آزمایشی از سایت developer android می‌باشد که در حال ترجمه می‌باشد.
برای پیوستن به تیم ترجمه و خواندن مستندات اینجا کلیک کنید.
MediaBrowserService / src / com.example.android.mediabrowserservice / utils /

LogHelper.java

1
/*
2
 * Copyright (C) 2014 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.example.android.mediabrowserservice.utils;
17
 
18
import android.util.Log;
19
 
20
public class LogHelper {
21
    public static void v(String tag, Object... messages) {
22
        log(tag, Log.VERBOSE, null, messages);
23
    }
24
 
25
    public static void d(String tag, Object... messages) {
26
        log(tag, Log.DEBUG, null, messages);
27
    }
28
 
29
    public static void i(String tag, Object... messages) {
30
        log(tag, Log.INFO, null, messages);
31
    }
32
 
33
    public static void w(String tag, Object... messages) {
34
        log(tag, Log.WARN, null, messages);
35
    }
36
 
37
    public static void w(String tag, Throwable t, Object... messages) {
38
        log(tag, Log.WARN, t, messages);
39
    }
40
 
41
    public static void e(String tag, Object... messages) {
42
        log(tag, Log.ERROR, null, messages);
43
    }
44
 
45
    public static void e(String tag, Throwable t, Object... messages) {
46
        log(tag, Log.ERROR, t, messages);
47
    }
48
 
49
    public static void log(String tag, int level, Throwable t, Object... messages) {
50
        if (messages != null && Log.isLoggable(tag, level)) {
51
            String message;
52
            if (messages.length == 1) {
53
                message = messages[0] == null ? null : messages[0].toString();
54
            } else {
55
                StringBuilder sb = new StringBuilder();
56
                for (Object m: messages) {
57
                    sb.append(m);
58
                }
59
                if (t != null) {
60
                    sb.append("\n").append(Log.getStackTraceString(t));