3 Copyright (C) 2011 Belledonne Communications, Grenoble, France
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 package org.linphone.core;
21 import static android.util.Log.DEBUG;
22 import static android.util.Log.ERROR;
23 import static android.util.Log.INFO;
24 import static android.util.Log.WARN;
27 * Convenient wrapper for Android logs.
29 * @author Guillaume Beraudo
31 public final class Log {
33 public static final String TAG = "Linphone";
34 private static final boolean useIsLoggable = false;
36 @SuppressWarnings(value="all")
37 private static boolean isLoggable(int level) {
38 return !useIsLoggable || android.util.Log.isLoggable(TAG, level);
41 public static void i(Object...objects) {
42 if (isLoggable(INFO)) {
43 android.util.Log.i(TAG, toString(objects));
46 public static void i(Throwable t, Object...objects) {
47 if (isLoggable(INFO)) {
48 android.util.Log.i(TAG, toString(objects), t);
53 public static void d(Object...objects) {
54 if (isLoggable(DEBUG)) {
55 android.util.Log.d(TAG, toString(objects));
58 public static void d(Throwable t, Object...objects) {
59 if (isLoggable(DEBUG)) {
60 android.util.Log.d(TAG, toString(objects), t);
64 public static void w(Object...objects) {
65 if (isLoggable(WARN)) {
66 android.util.Log.w(TAG, toString(objects));
69 public static void w(Throwable t, Object...objects) {
70 if (isLoggable(WARN)) {
71 android.util.Log.w(TAG, toString(objects), t);
75 public static void e(Object...objects) {
76 if (isLoggable(ERROR)) {
77 android.util.Log.e(TAG, toString(objects));
80 public static void e(Throwable t, Object...objects) {
81 if (isLoggable(ERROR)) {
82 android.util.Log.e(TAG, toString(objects), t);
87 * @throws RuntimeException always throw after logging the error message.
89 public static void f(Object...objects) {
90 if (isLoggable(ERROR)) {
91 android.util.Log.e(TAG, toString(objects));
92 throw new RuntimeException("Fatal error : " + toString(objects));
96 * @throws RuntimeException always throw after logging the error message.
98 public static void f(Throwable t, Object...objects) {
99 if (isLoggable(ERROR)) {
100 android.util.Log.e(TAG, toString(objects), t);
101 throw new RuntimeException("Fatal error : " + toString(objects), t);
105 private static String toString(Object...objects) {
106 StringBuilder sb = new StringBuilder();
107 for (Object o : objects) {
110 return sb.toString();