我正在使用 Jersey 2.25.1 客户端,无法获得任何日志输出。我看过 2.25.1 文档 - https://www.scribd.com/document/350321996/Jersey-Documentation-2-25-1-User-Guide - 并遵循他们对客户端日志记录的描述 -
ClientConfig clientConfig = new ClientConfig();
clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY_CLIENT, LoggingFeature.Verbosity.PAYLOAD_ANY);
Client client = ClientBuilder.newClient(clientConfig);
有没有我遗漏的附加步骤?该请求按预期工作。该应用程序在 Glassfish 服务器上运行并使用 SLF4J。我的理解是输出将记录到 server.log。
最佳答案
你还需要注册一个日志过滤器
clientConfig.register(new MyLogFilter());
您需要创建一个日志过滤器
class MyLogFilter implements ClientRequestFilter {
private static final Logger LOG = Logger.getLogger(MyLogFilter.class.getName());
@Override
public void filter(ClientRequestContext requestContext) throws IOException {
LOG.log(Level.INFO, requestContext.getEntity().toString()); // you can configure logging level here
}
}
关于jersey-2.0 - Jersey 2.25.1 客户端日志记录示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45992008/