Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a way to enable/disable internal debug logging #102

Merged
merged 1 commit into from
Jul 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public final class LightCycles {
private static final String TAG = LightCycles.class.getSimpleName();
private static final String ANDROID_PREFIX = "android.";
private static final String JAVA_PREFIX = "java.";
private static boolean debugLoggingEnabled = false;

@SuppressWarnings("PMD.EmptyCatchBlock")
public static void bind(LightCycleDispatcher<?> target) {
Expand All @@ -30,6 +31,16 @@ public static void bind(LightCycleDispatcher<?> target) {
}
}

public static void enableDebugLogging(boolean enabled) {
debugLoggingEnabled = enabled;
}

private static void debugLog(String message, Object... args) {
if (debugLoggingEnabled) {
Log.d(TAG, String.format(message, args));
}
}

private static String getInjectorClassName(String clsName) {
return clsName + "$LightCycleBinder";
}
Expand All @@ -39,15 +50,15 @@ private static Method findBinderForClass(Class<?> cls)
Method lightCycleInjectionMethod;
String clsName = cls.getName();
if (clsName.startsWith(ANDROID_PREFIX) || clsName.startsWith(JAVA_PREFIX)) {
Log.d(TAG, "MISS: Reached framework class. Abandoning search.");
debugLog("MISS: Reached framework class. Abandoning search.");
return null;
}
try {
Class<?> binder = Class.forName(getInjectorClassName(clsName));
lightCycleInjectionMethod = binder.getMethod("bind", cls);
Log.d(TAG, "HIT: Loaded LightCycle binder class.");
debugLog("HIT: Loaded LightCycle binder class.");
} catch (ClassNotFoundException e) {
Log.d(TAG, "Not found. Trying superclass " + cls.getSuperclass().getName());
debugLog("Not found. Trying superclass %s", cls.getSuperclass().getName());
lightCycleInjectionMethod = findBinderForClass(cls.getSuperclass());
}
return lightCycleInjectionMethod;
Expand Down