Open lsuski opened 10 years ago
Log is already an interface. You can create a class of your own that prints as little or as much as you want, and then set it on the RestAdapter, like so:
RestAdapter restAdapter = new RestAdapter.Builder().setLog(new MyLogImpl()).build();
What you print is up to you. I'd also suggest looking into the Emitter class, for help with printing.
Log is an interface but LogLevel is not. I would need to check message content passed to Log.log() method to reject e.g. headers, which is not very handy and require a knowledge of RestAdapter message format. Thanks.
BTW. Where is the class Emitter. I couldn't find it in Retrofit.
Huh, I apologize. I thought that was part of retrofit, looking closer, it's just an interface I made to abstract away that part of output.
I could envision a LogLevel builder that contains methods for setting the logging of headers, body, url, and status, among others. What else would you want to see in the builder?
Things that you mentioned + exceptions are sufficient for me. Thanks a lot for interest.
Writing this down so it's not in my head:
Loggers will get callbacks for request and response much like they do internally. Log level will become part of the default logging impl. You can replace the logger with one of your own.
@JakeWharton is that planned for 2.0 or also for the 1.x branch?
This is all 2.0 stuff. I'm trying to wrap up a 1.6 this week so I can start the work on 2.0 ASAP.
Another thing: how do we handle binary vs text data by default?
We need to be sure to hand the Class<?>
reference to the logger for which the events are being generated so that loggers can present the logs as if the interfaces themselves were generating them.
Came here looking for a solution to logging binary data - for now, I will use a different rest adapter. Do we need to consider the case where a TypedFile contains ASCII data and should potentially be logged?
It looks like 2.0.0-beta1 removed logging support altogether in commit 40bfa340bb back in January. Any idea when it might return?
Nope. Maybe never. Use OkHttp interceptors in the mean time.
On Mon, Aug 31, 2015 at 12:37 PM Hosam Aly notifications@github.com wrote:
It looks like 2.0.0-beta1 removed logging support altogether in commit 40bfa34 https://github.com/square/retrofit/commit/40bfa340bbff6b18c691f74b40e09f27b98ab920 back in January. Any idea when it might return?
— Reply to this email directly or view it on GitHub https://github.com/square/retrofit/issues/378#issuecomment-136423624.
Thanks. FWIW, here is an example for a logging interceptor for OkHttp: https://github.com/square/okhttp/wiki/Interceptors
Any chances to have default supported by Square logging interceptor implementation for OkHttp with logging of the bodies of the request and response like it was in Retrofit 1.x? I believe every second person would be interested in having that instead of tweaking the snippet from https://github.com/square/okhttp/wiki/Interceptors to log full request/response for debugging every time.
Is this already resolved by https://github.com/square/okhttp/pull/1874?
OkHttpClient client = new OkHttpClient();
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(Level.BASIC);
client.interceptors().add(logging);
No. That's logging at the HTTP layer which I mostly don't care about. Retrofit needs logging at the application layer using your types, not HTTP, for the representation.
On Sun, Sep 27, 2015, 3:33 PM Cemalettin Koc notifications@github.com wrote:
Is this already solved by square/okhttp#1874 https://github.com/square/okhttp/pull/1874?
OkHttpClient client = new OkHttpClient(); HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); logging.setLevel(Level.BASIC); client.interceptors().add(logging);
— Reply to this email directly or view it on GitHub https://github.com/square/retrofit/issues/378#issuecomment-143589285.
Hi, I'd like to log only request and response body along with http status code and execution time (no headers, urls and methods names). Is there possibility to make log level mechanism more flexible? For example use some interface or simple class with methods like isLogStatus(), isLogBody() etc. and ovveride it for own needs. Thanks