我在Android Project中使用了MockWebserver 3.14.9的旧版本,在运行UI测试时,我可以在LogCat中看到其日志。更新到最新的4.10.0之后,我看不到任何MockWeberver日志的请求和响应。看来,日志记录级别从,这没有更改。
if (logger.isLoggable(Level.FINE)) {
logger.fine(
"${this@MockWebServer} received request: $request and responded: $response"
)
}
我尝试调试它,并发现 if(logger.isloggable(level.fine))
始终返回false。
Here's the code for Logger.isLoggable
(
/**
* 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;
}
因此,通过在此方法中放置一个断点,我可以看到它返回false,因为请求的级别 fine> fine (( defined as 500
因此,上述PR是否将级别更改为 fine
不正确,因为它没有考虑到logger仍然是使用级别 info> info
更高的?
还是我缺少某些东西,有一种方法可以更改记录器级别或以其他方式查看MockWeberver的日志?
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?
发布评论
评论(1)
您可以在此处粘贴从调试记录文档中粘贴配置:
You can paste the configuration from the debug logging doc here:
https://square.github.io/okhttp/contribute/debug_logging/