]> sjero.net Git - linphone/blob - Log.java
replace vectores by arrays in linphone core api
[linphone] / Log.java
1 /*
2 Log.java
3 Copyright (C) 2011  Belledonne Communications, Grenoble, France
4
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.
9
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.
14
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.
18 */
19 package org.linphone.core;
20
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;
25
26 /**
27  * Convenient wrapper for Android logs.
28  *
29  * @author Guillaume Beraudo
30  */
31 public final class Log {
32
33         public static final String TAG = "Linphone";
34         private static final boolean useIsLoggable = false;
35
36         @SuppressWarnings(value="all")
37         private static boolean isLoggable(int level) {
38                 return !useIsLoggable || android.util.Log.isLoggable(TAG, level);
39         }
40
41         public static void i(Object...objects) {
42                 if (isLoggable(INFO)) {
43                         android.util.Log.i(TAG, toString(objects));
44                 }
45         }
46         public static void i(Throwable t, Object...objects) {
47                 if (isLoggable(INFO)) {
48                         android.util.Log.i(TAG, toString(objects), t);
49                 }
50         }
51
52         
53         public static void d(Object...objects) {
54                 if (isLoggable(DEBUG)) {
55                         android.util.Log.d(TAG, toString(objects));
56                 }
57         }
58         public static void d(Throwable t, Object...objects) {
59                 if (isLoggable(DEBUG)) {
60                         android.util.Log.d(TAG, toString(objects), t);
61                 }
62         }
63         
64         public static void w(Object...objects) {
65                 if (isLoggable(WARN)) {
66                         android.util.Log.w(TAG, toString(objects));
67                 }
68         }
69         public static void w(Throwable t, Object...objects) {
70                 if (isLoggable(WARN)) {
71                         android.util.Log.w(TAG, toString(objects), t);
72                 }
73         }
74         
75         public static void e(Object...objects) {
76                 if (isLoggable(ERROR)) {
77                         android.util.Log.e(TAG, toString(objects));
78                 }
79         }
80         public static void e(Throwable t, Object...objects) {
81                 if (isLoggable(ERROR)) {
82                         android.util.Log.e(TAG, toString(objects), t);
83                 }
84         }
85
86         /**
87          * @throws RuntimeException always throw after logging the error message.
88          */
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));
93                 }
94         }
95         /**
96          * @throws RuntimeException always throw after logging the error message.
97          */
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);
102                 }
103         }
104
105         private static String toString(Object...objects) {
106                 StringBuilder sb = new StringBuilder();
107                 for (Object o : objects) {
108                         sb.append(o);
109                 }
110                 return sb.toString();
111         }
112 }