HBASE-25688 Use CustomRequestLog instead of Slf4jRequestLog for jetty (#3075)

Signed-off-by: stack <stack@apache.org>
This commit is contained in:
Duo Zhang 2021-03-23 08:34:49 +08:00
parent b53f52dcd5
commit 7ff1d14959
2 changed files with 13 additions and 6 deletions

View File

@ -20,8 +20,9 @@ package org.apache.hadoop.hbase.http;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap;
import org.apache.hbase.thirdparty.org.eclipse.jetty.server.CustomRequestLog;
import org.apache.hbase.thirdparty.org.eclipse.jetty.server.RequestLog;
import org.apache.hbase.thirdparty.org.eclipse.jetty.server.Slf4jRequestLog;
import org.apache.hbase.thirdparty.org.eclipse.jetty.server.Slf4jRequestLogWriter;
/**
* RequestLog object for use with Http
@ -38,9 +39,9 @@ public final class HttpRequestLog {
name = lookup;
}
String loggerName = "http.requests." + name;
Slf4jRequestLog logger = new Slf4jRequestLog();
logger.setLoggerName(loggerName);
return logger;
Slf4jRequestLogWriter writer = new Slf4jRequestLogWriter();
writer.setLoggerName(loggerName);
return new CustomRequestLog(writer, CustomRequestLog.EXTENDED_NCSA_FORMAT);
}
private HttpRequestLog() {

View File

@ -17,6 +17,8 @@
*/
package org.apache.hadoop.hbase.http;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@ -27,8 +29,9 @@ import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.apache.hbase.thirdparty.org.eclipse.jetty.server.CustomRequestLog;
import org.apache.hbase.thirdparty.org.eclipse.jetty.server.RequestLog;
import org.apache.hbase.thirdparty.org.eclipse.jetty.server.Slf4jRequestLog;
import org.apache.hbase.thirdparty.org.eclipse.jetty.server.Slf4jRequestLogWriter;
@Category({ MiscTests.class, SmallTests.class })
public class TestHttpRequestLog {
@ -41,6 +44,9 @@ public class TestHttpRequestLog {
public void testAppenderDefined() {
RequestLog requestLog = HttpRequestLog.getRequestLog("test");
assertNotNull("RequestLog should not be null", requestLog);
assertEquals("Class mismatch", Slf4jRequestLog.class, requestLog.getClass());
assertThat(requestLog, instanceOf(CustomRequestLog.class));
CustomRequestLog crl = (CustomRequestLog) requestLog;
assertThat(crl.getWriter(), instanceOf(Slf4jRequestLogWriter.class));
assertEquals(CustomRequestLog.EXTENDED_NCSA_FORMAT, crl.getFormatString());
}
}