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

Different TAGs for each Adapter #431

Closed
long1eu opened this issue Aug 26, 2017 · 5 comments
Closed

Different TAGs for each Adapter #431

long1eu opened this issue Aug 26, 2017 · 5 comments
Milestone

Comments

@long1eu
Copy link
Contributor

long1eu commented Aug 26, 2017

It will be very useful to set a tag for each adapter. This will make debugging a lot easier when you have multiple adapters.

@davideas
Copy link
Owner

@thelong1EU, I think this is possible in somehow, now the Log system is custom and static, I will probably need to add new custom functions to accept dynamic TAG to the Log class.

Let's keep it aside for the moment.

@long1eu
Copy link
Contributor Author

long1eu commented Aug 27, 2017 via email

@davideas
Copy link
Owner

davideas commented Sep 2, 2017

@thelong1EU, I couldn't find another "quick" solution than this:

Log.java

public static void useTag(@Nullable String customTag) {
    Log.customTag = customTag;
}

private static String getTag() {
    if (customTag != null) return customTag;
    StackTraceElement traceElement = new Throwable().getStackTrace()[2];
    ......
}

Using static instances and non-static instance fields, it continues to increase the counter no stop, every time you create an instance (opening/closing activities). Instead, by defining a custom tag, you can set it in create phase and restore/clear at destroy phase. Usage from 2nd Activity:

Activity2.java

onCreate() {
   Log.useTag("FlexibleAdapter2");
   mAdapter = new FlexibleAdapter();
}
onDestroy() {
   // Because it's static we need to restore previous value for 1st instance
   Log.useTag(null); or Log.useTag("FlexibleAdapter1");
}

However, this has a defect when used with Observables that receive a callback to update the list in another Activity, it will log with the latest tag unless is set/restored everytime.

Another solution would be to have non-static internal Logger initialized inside with the default or from a static setter before creation. Like this:

Activity2.java

FlexibleAdapter.useTag("FlexibleAdapter2");
mAdapter = new FlexibleAdapter();

Anyway, the others helper classes around the Adapter won't take the custom tag!

@davideas
Copy link
Owner

davideas commented Sep 2, 2017

@thelong1EU, I opted for a mixed solution, please see the next commit in CustomTags branch.
You can also see the javaDoc description of the new Logger class that now works in collaboration with Log. Now FlexibleAdapter instances can have custom tag and the tag reset is automatic.

@long1eu
Copy link
Contributor Author

long1eu commented Sep 2, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants