|
2 | 2 |
|
3 | 3 | import androidx.annotation.IntDef; |
4 | 4 | import androidx.annotation.Nullable; |
| 5 | + |
5 | 6 | import android.util.Log; |
6 | 7 |
|
7 | 8 | import com.polidea.rxandroidble2.LogConstants; |
8 | 9 | import com.polidea.rxandroidble2.LogOptions; |
9 | 10 |
|
10 | 11 | import com.polidea.rxandroidble2.internal.logger.LoggerSetup; |
| 12 | +import com.polidea.rxandroidble2.internal.logger.LoggerUtil; |
| 13 | +import com.polidea.rxandroidble2.internal.logger.LoggerUtilBluetoothServices; |
| 14 | + |
11 | 15 | import java.lang.annotation.Retention; |
12 | 16 | import java.lang.annotation.RetentionPolicy; |
| 17 | +import java.util.Arrays; |
| 18 | +import java.util.List; |
13 | 19 | import java.util.regex.Matcher; |
14 | 20 | import java.util.regex.Pattern; |
15 | 21 |
|
@@ -142,12 +148,22 @@ private static String createTag() { |
142 | 148 | return tag; |
143 | 149 | } |
144 | 150 |
|
145 | | - StackTraceElement[] stackTrace = new Throwable().getStackTrace(); |
146 | | - if (stackTrace.length < 5) { |
| 151 | + List<String> ignoreClasses = Arrays.asList( |
| 152 | + RxBleLog.class.getName(), |
| 153 | + LoggerUtil.class.getName(), |
| 154 | + LoggerUtilBluetoothServices.class.getName()); |
| 155 | + |
| 156 | + Throwable throwable = new Throwable(); |
| 157 | + StackTraceElement[] stackTrace = throwable.getStackTrace(); |
| 158 | + int i = 0; |
| 159 | + while (i < stackTrace.length && ignoreClasses.contains(stackTrace[i].getClassName())) { |
| 160 | + i++; |
| 161 | + } |
| 162 | + if (stackTrace.length <= i) { |
147 | 163 | throw new IllegalStateException( |
148 | | - "Synthetic stacktrace didn't have enough elements: are you using proguard?"); |
| 164 | + "Synthetic stacktrace didn't have enough elements: are you using proguard?", throwable); |
149 | 165 | } |
150 | | - tag = stackTrace[4].getClassName(); |
| 166 | + tag = stackTrace[i].getClassName(); |
151 | 167 | Matcher m = ANONYMOUS_CLASS.matcher(tag); |
152 | 168 | if (m.find()) { |
153 | 169 | tag = m.replaceAll(""); |
@@ -249,11 +265,13 @@ public static boolean isAtLeast(int expectedLogLevel) { |
249 | 265 | return loggerSetup.logLevel <= expectedLogLevel; |
250 | 266 | } |
251 | 267 |
|
252 | | - public static @LogConstants.MacAddressLogSetting int getMacAddressLogSetting() { |
| 268 | + @LogConstants.MacAddressLogSetting |
| 269 | + public static int getMacAddressLogSetting() { |
253 | 270 | return loggerSetup.macAddressLogSetting; |
254 | 271 | } |
255 | 272 |
|
256 | | - public static @LogConstants.UuidLogSetting int getUuidLogSetting() { |
| 273 | + @LogConstants.UuidLogSetting |
| 274 | + public static int getUuidLogSetting() { |
257 | 275 | return loggerSetup.uuidLogSetting; |
258 | 276 | } |
259 | 277 |
|
|
0 commit comments