### Question:
HttpRequestLog { public static RequestLog getRequestLog(String name) { String lookup = SERVER_TO_COMPONENT.get(name); if (lookup != null) { name = lookup; } String loggerName = "http.requests." + name; String appenderName = name + "requestlog"; Log logger = LogFactory.getLog(loggerName); boolean isLog4JLogger; try { isLog4JLogger = logger instanceof Log4JLogger; } catch (NoClassDefFoundError err) { LOG.debug("Could not load Log4JLogger class", err); isLog4JLogger = false; } if (isLog4JLogger) { Log4JLogger httpLog4JLog = (Log4JLogger) logger; org.apache.log4j.Logger httpLogger = httpLog4JLog.getLogger(); Appender appender = null; try { appender = httpLogger.getAppender(appenderName); } catch (LogConfigurationException e) { LOG.warn("Http request log for {} could not be created", loggerName); throw e; } if (appender == null) { LOG.info("Http request log for {} is not defined", loggerName); return null; } if (appender instanceof HttpRequestLogAppender) { HttpRequestLogAppender requestLogAppender = (HttpRequestLogAppender) appender; AsyncRequestLogWriter logWriter = new AsyncRequestLogWriter(); logWriter.setFilename(requestLogAppender.getFilename()); logWriter.setRetainDays(requestLogAppender.getRetainDays()); return new CustomRequestLog(logWriter, CustomRequestLog.EXTENDED_NCSA_FORMAT); } else { LOG.warn("Jetty request log for {} was of the wrong class", loggerName); return null; } } else { LOG.warn("Jetty request log can only be enabled using Log4j"); return null; } } private  HttpRequestLog(); static RequestLog getRequestLog(String name); static final Logger LOG; }### Answer:
@Test public void testAppenderUndefined() { RequestLog requestLog = HttpRequestLog.getRequestLog("test"); assertNull("RequestLog should be null", requestLog); }
@Test public void testAppenderDefined() { HttpRequestLogAppender requestLogAppender = new HttpRequestLogAppender(); requestLogAppender.setName("testrequestlog"); Logger.getLogger("http.requests.test").addAppender(requestLogAppender); RequestLog requestLog = HttpRequestLog.getRequestLog("test"); Logger.getLogger("http.requests.test").removeAppender(requestLogAppender); assertNotNull("RequestLog should not be null", requestLog); assertEquals("Class mismatch", CustomRequestLog.class, requestLog.getClass()); }