1 /* 2 * Copyright (C) 2020 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.rotary; 18 19 import android.os.Build; 20 import android.util.Log; 21 22 import androidx.annotation.NonNull; 23 24 /** 25 * Utility class for logging. 26 */ 27 class L { 28 private static final String TAG = "RotaryController"; 29 30 /** Logs verbose level logs if loggable or on a debug build. */ v(@onNull String msg)31 static void v(@NonNull String msg) { 32 if (Log.isLoggable(TAG, Log.VERBOSE) || Build.IS_DEBUGGABLE) { 33 Log.v(TAG, msg); 34 } 35 } 36 37 /** Logs debug level logs if loggable or on a debug build. */ d(@onNull String msg)38 static void d(@NonNull String msg) { 39 if (Log.isLoggable(TAG, Log.DEBUG) || Build.IS_DEBUGGABLE) { 40 Log.d(TAG, msg); 41 } 42 } 43 44 /** Logs info level logs if loggable or on a debug build. */ i(@onNull String msg)45 static void i(@NonNull String msg) { 46 if (Log.isLoggable(TAG, Log.INFO) || Build.IS_DEBUGGABLE) { 47 Log.i(TAG, msg); 48 } 49 } 50 51 /** Logs warning level logs if loggable or on a debug build. */ w(@onNull String msg)52 static void w(@NonNull String msg) { 53 if (Log.isLoggable(TAG, Log.WARN) || Build.IS_DEBUGGABLE) { 54 Log.w(TAG, msg); 55 } 56 } 57 58 /** Logs error level logs if loggable or on a debug build. */ e(@onNull String msg)59 static void e(@NonNull String msg) { 60 if (Log.isLoggable(TAG, Log.ERROR) || Build.IS_DEBUGGABLE) { 61 Log.e(TAG, msg); 62 } 63 } 64 65 /** Logs conditional logs if loggable or on a debug build. */ successOrFailure(@onNull String msg, boolean success)66 static void successOrFailure(@NonNull String msg, boolean success) { 67 if (success) { 68 d(msg + " succeeded"); 69 } else { 70 w(msg + " failed"); 71 } 72 } 73 } 74