-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
Conditionally-logging interceptor sample #4159
Conversation
Output:
|
* Retrofit service functions which are annotated with this class will have their HTTP calls | ||
* logged. You must add [ConditionalLoggingInterceptor] to your [OkHttpClient] for this to work. | ||
*/ | ||
annotation class LogInterceptor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Should this just be Log
? It's kind of weird to think about interceptors as a concept in your service definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started with Log
and it looked weird, but I don't care. Put back.
override fun intercept(chain: Interceptor.Chain): Response { | ||
val request = chain.request() | ||
request.tag(Invocation::class.java)?.let { invocation -> | ||
if (invocation.method().isAnnotationPresent(LogInterceptor::class.java)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the annotation need to have a specific retention for this to reliably work? Also, only an Android issue, but would r8 rules be needed as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default is runtime retention which should be fine. These are only samples so R8 is an exercise left for the reader. It should generally be okay without any rules, I think.
15827f9
to
8c2b181
Compare
Closes #4156
CHANGELOG.md
's "Unreleased" section has been updated, if applicable.