|
1 /* |
|
2 * Copyright 2012 Google Inc. |
|
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.google.android.apps.iosched.util; |
|
18 |
|
19 import com.beem.project.beem.BuildConfig; |
|
20 |
|
21 import android.util.Log; |
|
22 |
|
23 /** |
|
24 * Helper methods that make logging more consistent throughout the app. |
|
25 */ |
|
26 public class LogUtils { |
|
27 private static final String LOG_PREFIX = "Beem"; |
|
28 private static final int LOG_PREFIX_LENGTH = LOG_PREFIX.length(); |
|
29 private static final int MAX_LOG_TAG_LENGTH = 23; |
|
30 |
|
31 public static String makeLogTag(String str) { |
|
32 if (str.length() > MAX_LOG_TAG_LENGTH - LOG_PREFIX_LENGTH) { |
|
33 return LOG_PREFIX + str.substring(0, MAX_LOG_TAG_LENGTH - LOG_PREFIX_LENGTH - 1); |
|
34 } |
|
35 |
|
36 return LOG_PREFIX + str; |
|
37 } |
|
38 |
|
39 /** |
|
40 * WARNING: Don't use this when obfuscating class names with Proguard! |
|
41 */ |
|
42 public static String makeLogTag(Class cls) { |
|
43 return makeLogTag(cls.getSimpleName()); |
|
44 } |
|
45 |
|
46 public static void LOGD(final String tag, String message) { |
|
47 if (Log.isLoggable(tag, Log.DEBUG)) { |
|
48 Log.d(tag, message); |
|
49 } |
|
50 } |
|
51 |
|
52 public static void LOGD(final String tag, String message, Throwable cause) { |
|
53 if (Log.isLoggable(tag, Log.DEBUG)) { |
|
54 Log.d(tag, message, cause); |
|
55 } |
|
56 } |
|
57 |
|
58 public static void LOGV(final String tag, String message) { |
|
59 //noinspection PointlessBooleanExpression,ConstantConditions |
|
60 if (BuildConfig.DEBUG && Log.isLoggable(tag, Log.VERBOSE)) { |
|
61 Log.v(tag, message); |
|
62 } |
|
63 } |
|
64 |
|
65 public static void LOGV(final String tag, String message, Throwable cause) { |
|
66 //noinspection PointlessBooleanExpression,ConstantConditions |
|
67 if (BuildConfig.DEBUG && Log.isLoggable(tag, Log.VERBOSE)) { |
|
68 Log.v(tag, message, cause); |
|
69 } |
|
70 } |
|
71 |
|
72 public static void LOGI(final String tag, String message) { |
|
73 Log.i(tag, message); |
|
74 } |
|
75 |
|
76 public static void LOGI(final String tag, String message, Throwable cause) { |
|
77 Log.i(tag, message, cause); |
|
78 } |
|
79 |
|
80 public static void LOGW(final String tag, String message) { |
|
81 Log.w(tag, message); |
|
82 } |
|
83 |
|
84 public static void LOGW(final String tag, String message, Throwable cause) { |
|
85 Log.w(tag, message, cause); |
|
86 } |
|
87 |
|
88 public static void LOGE(final String tag, String message) { |
|
89 Log.e(tag, message); |
|
90 } |
|
91 |
|
92 public static void LOGE(final String tag, String message, Throwable cause) { |
|
93 Log.e(tag, message, cause); |
|
94 } |
|
95 |
|
96 private LogUtils() { |
|
97 } |
|
98 } |