1 /*
2  * Copyright (C) 2018 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 
17 package com.android.car.dialer.log;
18 
19 import android.util.Log;
20 
21 import androidx.annotation.NonNull;
22 
23 /**
24  * Util class for logging.
25  */
26 public class L {
27 
28     /**
29      * Logs verbose level logs if loggable.
30      *
31      * <p>@see String#format(String, Object...) for formatting log string.
32      */
v(String tag, @NonNull String msg, Object... args)33     public static void v(String tag, @NonNull String msg, Object... args) {
34         if (Log.isLoggable(tag, Log.VERBOSE)) {
35             Log.v(tag, String.format(msg, args));
36         }
37     }
38 
39     /**
40      * Logs debug level logs if loggable.
41      *
42      * <p>@see String#format(String, Object...) for formatting log string.
43      */
d(String tag, @NonNull String msg, Object... args)44     public static void d(String tag, @NonNull String msg, Object... args) {
45         if (Log.isLoggable(tag, Log.DEBUG)) {
46             Log.d(tag, String.format(msg, args));
47         }
48     }
49 
50     /**
51      * Logs info level logs if loggable.
52      *
53      * <p>@see String#format(String, Object...) for formatting log string.
54      */
i(String tag, @NonNull String msg, Object... args)55     public static void i(String tag, @NonNull String msg, Object... args) {
56         if (Log.isLoggable(tag, Log.INFO)) {
57             Log.i(tag, String.format(msg, args));
58         }
59     }
60 
61     /**
62      * Logs warning level logs if loggable.
63      *
64      * <p>@see String#format(String, Object...) for formatting log string.
65      */
w(String tag, @NonNull String msg, Object... args)66     public static void w(String tag, @NonNull String msg, Object... args) {
67         if (Log.isLoggable(tag, Log.WARN)) {
68             Log.w(tag, String.format(msg, args));
69         }
70     }
71 
72     /**
73      * Logs error level logs.
74      *
75      * <p>@see String#format(String, Object...) for formatting log string.
76      */
e(String tag, @NonNull String msg, Object... args)77     public static void e(String tag, @NonNull String msg, Object... args) {
78         Log.e(tag, String.format(msg, args));
79     }
80 
81     /**
82      * Logs warning level logs.
83      *
84      * <p>@see String#format(String, Object...) for formatting log string.
85      */
e(String tag, Exception e, @NonNull String msg, Object... args)86     public static void e(String tag, Exception e, @NonNull String msg, Object... args) {
87         Log.e(tag, String.format(msg, args), e);
88     }
89 }
90