I was using an old version of MockWebServer 3.14.9 in my Android project and I could see its logs in the logcat when running my UI Tests. After updating to the latest 4.10.0 I can't see any MockWebServer logs for requests and responses. It appears that the logging level was changed from INFO to FINE in this PR. As you can see in the latest code, that hasn't changed.
if (logger.isLoggable(Level.FINE)) {
logger.fine(
"${this@MockWebServer} received request: $request and responded: $response"
)
}
I tried debugging it and found that if (logger.isLoggable(Level.FINE))
always returns false.
Here's the code for Logger.isLoggable
(source):
/**
* Check if a message of the given level would actually be logged
* by this logger. This check is based on the Loggers effective level,
* which may be inherited from its parent.
*
* @param level a message logging level
* @return true if the given message level is currently being logged.
*/
public boolean isLoggable(Level level) {
int levelValue = config.levelValue;
if (level.intValue() < levelValue || levelValue == offValue) {
return false;
}
return true;
}
So by putting a breakpoint in this method I could see that it returns false because the requested level FINE
(defined as 500 here), is apparently lower than the Logger's level INFO
(defined as 800 here).
So was the aforementioned PR to change the level to FINE
incorrect as it didn't consider that the Logger was still created with level INFO
which is higher?
Or is there something I'm missing and there is a way to change the Logger level or otherwise see the logs from MockWebServer?
You can paste the configuration from the debug logging doc here: https://square.github.io/okhttp/contribute/debug_logging/
OkHttpDebugLogging.enable(MockWebServer::class)