HttpRequestLog { public static RequestLog getRequestLog(String name) { String lookup = serverToComponent.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; NCSARequestLog requestLog = new NCSARequestLog(); requestLog.setFilename(requestLogAppender.getFilename()); requestLog.setRetainDays(requestLogAppender.getRetainDays()); return requestLog; } 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; } }  static RequestLog getRequestLog(String name); static final Logger LOG; }
@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", NCSARequestLog.class, requestLog.getClass()); }