19
19
* ReVanced specific logger. Logging is done to standard device log (accessible thru ADB),
20
20
* and additionally accessible thru {@link LogBufferManager}.
21
21
*
22
- * All methods are thread safe.
22
+ * All methods are thread safe, and are safe to call even
23
+ * if {@link Utils#getContext()} is not available.
23
24
*/
24
25
public class Logger {
25
26
@@ -138,6 +139,14 @@ private static void logInternal(LogLevel logLevel, LogMessage message, @Nullable
138
139
}
139
140
}
140
141
142
+ private static boolean includeStackTrace () {
143
+ return Utils .context != null && DEBUG_STACKTRACE .get ();
144
+ }
145
+
146
+ private static boolean shouldShowErrorToast () {
147
+ return Utils .context != null && DEBUG_TOAST_ON_ERROR .get ();
148
+ }
149
+
141
150
/**
142
151
* Logs debug messages under the outer class name of the code calling this method.
143
152
* <p>
@@ -158,7 +167,7 @@ public static void printDebug(LogMessage message) {
158
167
*/
159
168
public static void printDebug (LogMessage message , @ Nullable Exception ex ) {
160
169
if (DEBUG .get ()) {
161
- logInternal (LogLevel .DEBUG , message , ex , DEBUG_STACKTRACE . get (), false );
170
+ logInternal (LogLevel .DEBUG , message , ex , includeStackTrace (), false );
162
171
}
163
172
}
164
173
@@ -173,7 +182,7 @@ public static void printInfo(LogMessage message) {
173
182
* Logs information messages using the outer class name of the code calling this method.
174
183
*/
175
184
public static void printInfo (LogMessage message , @ Nullable Exception ex ) {
176
- logInternal (LogLevel .INFO , message , ex , DEBUG_STACKTRACE . get (), false );
185
+ logInternal (LogLevel .INFO , message , ex , includeStackTrace (), false );
177
186
}
178
187
179
188
/**
@@ -194,22 +203,6 @@ public static void printException(LogMessage message) {
194
203
* @param ex exception (optional)
195
204
*/
196
205
public static void printException (LogMessage message , @ Nullable Throwable ex ) {
197
- logInternal (LogLevel .ERROR , message , ex , DEBUG_STACKTRACE .get (), DEBUG_TOAST_ON_ERROR .get ());
198
- }
199
-
200
- /**
201
- * Logging to use if {@link BaseSettings#DEBUG} or {@link Utils#getContext()} may not be initialized.
202
- * Normally this method should not be used.
203
- */
204
- public static void initializationInfo (LogMessage message ) {
205
- logInternal (LogLevel .INFO , message , null , false , false );
206
- }
207
-
208
- /**
209
- * Logging to use if {@link BaseSettings#DEBUG} or {@link Utils#getContext()} may not be initialized.
210
- * Normally this method should not be used.
211
- */
212
- public static void initializationException (LogMessage message , @ Nullable Exception ex ) {
213
- logInternal (LogLevel .ERROR , message , ex , false , false );
206
+ logInternal (LogLevel .ERROR , message , ex , includeStackTrace (), shouldShowErrorToast ());
214
207
}
215
208
}
0 commit comments