diff options
| author | Dan Harms <danharms@google.com> | 2020-01-07 16:06:17 -0800 |
|---|---|---|
| committer | Dan Harms <danharms@google.com> | 2020-01-13 10:34:06 -0800 |
| commit | 0f2fc6f32d28d713d89ee25130d8d580ab3cbfd3 (patch) | |
| tree | 972ef4815e12995d0eef71c7aa52bb34dfc8db34 /connected-device-lib/src | |
| parent | 298e6f4107968f112d41654d8e7b9825cb8a2e2a (diff) | |
| download | platform_packages_apps_Car_libs-0f2fc6f32d28d713d89ee25130d8d580ab3cbfd3.tar.gz platform_packages_apps_Car_libs-0f2fc6f32d28d713d89ee25130d8d580ab3cbfd3.tar.bz2 platform_packages_apps_Car_libs-0f2fc6f32d28d713d89ee25130d8d580ab3cbfd3.zip | |
Convert SafeLog to Java
Bug: 143651521
Test: Manual
Change-Id: I0bbde2961afb8b12ff53576ec5e586c40c55e274
Diffstat (limited to 'connected-device-lib/src')
| -rw-r--r-- | connected-device-lib/src/com/android/car/connecteddevice/util/SafeLog.java | 70 | ||||
| -rw-r--r-- | connected-device-lib/src/com/android/car/connecteddevice/util/SafeLog.kt | 56 |
2 files changed, 70 insertions, 56 deletions
diff --git a/connected-device-lib/src/com/android/car/connecteddevice/util/SafeLog.java b/connected-device-lib/src/com/android/car/connecteddevice/util/SafeLog.java new file mode 100644 index 00000000..6ab18ce3 --- /dev/null +++ b/connected-device-lib/src/com/android/car/connecteddevice/util/SafeLog.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2020 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 com.android.car.connecteddevice.util; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.util.Log; + +/** + * Convenience logging methods that respect whitelisted tags. + */ +public class SafeLog { + + private SafeLog() { } + + /** Log message if tag is whitelisted for {@code Log.VERBOSE}. */ + public static void logv(@NonNull String tag, @NonNull String message) { + if (Log.isLoggable(tag, Log.VERBOSE)) { + Log.v(tag, message); + } + } + + /** Log message if tag is whitelisted for {@code Log.INFO}. */ + public static void logi(@NonNull String tag, @NonNull String message) { + if (Log.isLoggable(tag, Log.INFO)) { + Log.i(tag, message); + } + } + + /** Log message if tag is whitelisted for {@code Log.DEBUG}. */ + public static void logd(@NonNull String tag, @NonNull String message) { + if (Log.isLoggable(tag, Log.DEBUG)) { + Log.d(tag, message); + } + } + + /** Log message if tag is whitelisted for {@code Log.WARN}. */ + public static void logw(@NonNull String tag, @NonNull String message) { + if (Log.isLoggable(tag, Log.WARN)) { + Log.w(tag, message); + } + } + + /** Log message if tag is whitelisted for {@code Log.ERROR}. */ + public static void loge(@NonNull String tag, @NonNull String message) { + loge(tag, message, /* exception = */ null); + } + + /** Log message and optional exception if tag is whitelisted for {@code Log.ERROR}. */ + public static void loge(@NonNull String tag, @NonNull String message, + @Nullable Exception exception) { + if (Log.isLoggable(tag, Log.ERROR)) { + Log.e(tag, message, exception); + } + } +} diff --git a/connected-device-lib/src/com/android/car/connecteddevice/util/SafeLog.kt b/connected-device-lib/src/com/android/car/connecteddevice/util/SafeLog.kt deleted file mode 100644 index 9a21a545..00000000 --- a/connected-device-lib/src/com/android/car/connecteddevice/util/SafeLog.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2019 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. - */ - -@file:JvmName("SafeLog") -package com.android.car.connecteddevice.util - -import android.util.Log - -/** Log [message] if [tag] is whitelisted for `Log.VERBOSE` */ -fun logv(tag: String, message: String) { - if (Log.isLoggable(tag, Log.VERBOSE)) { - Log.v(tag, message) - } -} - -/** Log [message] if [tag] is whitelisted for `Log.INFO` */ -fun logi(tag: String, message: String) { - if (Log.isLoggable(tag, Log.INFO)) { - Log.i(tag, message) - } -} - -/** Log [message] if [tag] is whitelisted for `Log.DEBUG` */ -fun logd(tag: String, message: String) { - if (Log.isLoggable(tag, Log.DEBUG)) { - Log.d(tag, message) - } -} - -/** Log [message] if [tag] is whitelisted for `Log.WARN` */ -fun logw(tag: String, message: String) { - if (Log.isLoggable(tag, Log.WARN)) { - Log.w(tag, message) - } -} - -/** Log [message] if [tag] is whitelisted for `Log.ERROR` */ -@JvmOverloads -fun loge(tag: String, message: String, throwable: Throwable? = null) { - if (Log.isLoggable(tag, Log.ERROR)) { - Log.e(tag, message, throwable) - } -} |
