• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.timezone.location.provider.core;
17 
18 import android.util.Log;
19 
20 import androidx.annotation.NonNull;
21 import androidx.annotation.Nullable;
22 
23 import com.android.timezone.location.common.PiiLoggable;
24 
25 import java.time.Duration;
26 import java.time.Instant;
27 
28 /** Contains helper methods for logging. */
29 public final class LogUtils {
30 
31     public static final String LOG_TAG = "OfflineLTZP";
32     private static final boolean DBG = false;
33 
LogUtils()34     private LogUtils() {}
35 
36     /** Formats the supplied system clock timestamp for debug output. */
formatUtcTime(long timeMillis)37     public static String formatUtcTime(long timeMillis) {
38         return Instant.ofEpochMilli(timeMillis).toString();
39     }
40 
41     /** Formats the supplied elapse realtime clock timestamp  for debug output. */
formatElapsedRealtimeMillis(long elapsedRealtimeMillis)42     public static String formatElapsedRealtimeMillis(long elapsedRealtimeMillis) {
43         return Duration.ofMillis(elapsedRealtimeMillis).toString();
44     }
45 
46     /** Logs at debug level when debug logging is enabled via {@link #DBG}. */
logDebug(@onNull PiiLoggable piiLoggable)47     public static void logDebug(@NonNull PiiLoggable piiLoggable) {
48         if (DBG) {
49             Log.d(LOG_TAG, piiLoggable.toString());
50         }
51     }
52 
53     /** Logs at debug level when debug logging is enabled via {@link #DBG}. */
logDebug(@onNull String msg)54     public static void logDebug(@NonNull String msg) {
55         if (DBG) {
56             Log.d(LOG_TAG, msg);
57         }
58     }
59 
60     /** Logs at warn level. */
logWarn(@onNull PiiLoggable piiLoggable)61     public static void logWarn(@NonNull PiiLoggable piiLoggable) {
62         Log.w(LOG_TAG, piiLoggable.toString());
63     }
64 
65     /** Logs at warn level. */
logWarn(@onNull String msg)66     public static void logWarn(@NonNull String msg) {
67         Log.w(LOG_TAG, msg);
68     }
69 
70     /** Logs at warn level. */
logWarn(@onNull PiiLoggable piiLoggable, @Nullable Throwable t)71     public static void logWarn(@NonNull PiiLoggable piiLoggable, @Nullable Throwable t) {
72         Log.w(LOG_TAG, piiLoggable.toString(), t);
73     }
74 
75     /** Logs at warn level. */
logWarn(@onNull String msg, @Nullable Throwable t)76     public static void logWarn(@NonNull String msg, @Nullable Throwable t) {
77         Log.w(LOG_TAG, msg, t);
78     }
79 }
80