Java 类org.eclipse.jetty.server.NCSARequestLog 实例源码

项目:jetty-console    文件:RequestLogPlugin.java   
@Override
public void customizeServer(Server server) {
    if(logFile != null) {
    HandlerCollection rootHandler = (HandlerCollection) server.getHandler();

    List<Handler> handlers = new ArrayList<Handler>();

    handlers.addAll(Arrays.asList(rootHandler.getHandlers()));

    RequestLogHandler requestLogHandler = new RequestLogHandler();

    NCSARequestLog requestLog = new NCSARequestLog(logFile.getAbsolutePath());
    requestLog.setRetainDays(0);
    requestLog.setAppend(true);
    requestLog.setExtended(extended);
    requestLog.setLogTimeZone("GMT");
    requestLogHandler.setRequestLog(requestLog);

    handlers.add(requestLogHandler);

    rootHandler.setHandlers(handlers.toArray(new Handler[handlers.size()]));

    }
}
项目:scouter    文件:WebAppMain.java   
private static RequestLogHandler setRequestLogHandler() {
    ConfigureAdaptor conf = ConfigureManager.getConfigure();

    NCSARequestLog requestLog = new NCSARequestLog();
    requestLog.setFilename("./logs/http-request-yyyy_mm_dd.log");
    requestLog.setFilenameDateFormat("yyyy_MM_dd");
    requestLog.setRetainDays(conf.getLogKeepDays());
    requestLog.setAppend(true);
    requestLog.setExtended(true);
    requestLog.setLogCookies(false);
    requestLog.setLogTimeZone(TimeZone.getDefault().getID());
    RequestLogHandler requestLogHandler = new RequestLogHandler();
    requestLogHandler.setRequestLog(requestLog);

    return requestLogHandler;
}
项目:ConfigService    文件:Main.java   
private NCSARequestLog buildRequestLog() {
    NCSARequestLog requestLog = new NCSARequestLog("logs/jetty-yyyy_mm_dd.request.log");
    requestLog.setAppend(true);
    requestLog.setExtended(true);
    requestLog.setLogTimeZone("GMT");

    return requestLog;
}
项目:cs601    文件:MinimalServletsWithLogging.java   
public static void main(String[] args) throws Exception {
       // Create a basic jetty server object that will listen on port 8080.  Note that if you set this to port 0
       // then a randomly available port will be assigned that you can either look in the logs for the port,
       // or programmatically obtain it for use in test cases.
       Server server = new Server(8080);
    HandlerCollection handlers = new HandlerCollection();
    server.setHandler(handlers);

       ServletHandler servlet = new ServletHandler();
    servlet.addServletWithMapping(HelloServlet.class, "/*");
    handlers.addHandler(servlet);

    handlers.addHandler(new DefaultHandler()); // must be after servlet it seems

    // log using NCSA (common log format)
    // http://en.wikipedia.org/wiki/Common_Log_Format
    NCSARequestLog requestLog = new NCSARequestLog();
    requestLog.setFilename("/tmp/yyyy_mm_dd.request.log");
    requestLog.setFilenameDateFormat("yyyy_MM_dd");
    requestLog.setRetainDays(90);
    requestLog.setAppend(true);
    requestLog.setExtended(true);
    requestLog.setLogCookies(false);
    requestLog.setLogTimeZone("GMT");
    RequestLogHandler requestLogHandler = new RequestLogHandler();
    requestLogHandler.setRequestLog(requestLog);
    handlers.addHandler(requestLogHandler);

    // Start things up! By using the server.join() the server thread will join with the current thread.
    // See "http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#join()" for more details.
    server.start();
    server.join();
}
项目:hbase    文件:TestHttpRequestLog.java   
@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());
}
项目:cloudstack    文件:ServerDaemon.java   
private RequestLog createRequestLog() {
    final NCSARequestLog log = new NCSARequestLog();
    final File logPath = new File(accessLogFile);
    final File parentFile = logPath.getParentFile();
    if (parentFile != null) {
        parentFile.mkdirs();
    }
    log.setFilename(logPath.getPath());
    log.setAppend(true);
    log.setLogTimeZone("GMT");
    log.setLogLatency(true);
    return log;
}
项目:hbase    文件:HttpRequestLog.java   
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";

    org.apache.log4j.Logger httpLogger = getLog4jLogger(loggerName);

    if (httpLogger == null) {
      LOG.warn("Jetty request log can only be enabled using Log4j");
      return null;
    }

    Appender appender = null;

    try {
      appender = httpLogger.getAppender(appenderName);
    } catch (LogConfigurationException e) {
      LOG.warn("Http request log for " + loggerName
          + " could not be created");
      throw e;
    }

    if (appender == null) {
      LOG.info("Http request log for " + loggerName
          + " is not defined");
      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 " + loggerName
          + " was of the wrong class");
      return null;
    }
  }
项目:stickypunch    文件:JettyService.java   
public static Server create(HttpConfiguration configuration) throws Exception {
    Server server = new Server();

    SelectChannelConnector connector = new InstrumentedSelectChannelConnector(configuration.listenAddress.getPort());
    connector.setHost(configuration.listenAddress.getHostName());
    QueuedThreadPool queuedThreadPool = new InstrumentedQueuedThreadPool();
    queuedThreadPool.setMaxThreads(configuration.numHttpWorkers);
    connector.setThreadPool(queuedThreadPool);
    queuedThreadPool.start();

    server.setConnectors(new Connector[]{connector});
    server.setSendServerVersion(true);
    server.setSendDateHeader(true);
    server.setStopAtShutdown(true);
    server.setGracefulShutdown((int) TimeUnit.SECONDS.toMillis(5));

    ServletContextHandler root = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
    root.setContextPath("/");

    server.setHandler(new InstrumentedHandler(root));

    // Jersey
    root.addServlet(buildJerseyServlet(), "/*");

    NCSARequestLog requestLog = new NCSARequestLog(configuration.httpLogFileName);
    requestLog.setRetainDays(90);
    requestLog.setAppend(true);
    requestLog.setExtended(true);
    requestLog.setLogTimeZone("GMT");
    requestLog.setLogLatency(true);
    requestLog.setLogDispatch(true);

    RequestLogHandler requestLogHandler = new RequestLogHandler();
    requestLogHandler.setRequestLog(requestLog);
    root.setHandler(requestLogHandler);

    connector.setStatsOn(true);
    StatisticsHandler statisticsHandler = new StatisticsHandler();
    statisticsHandler.setServer(server);

    requestLogHandler.setHandler(statisticsHandler);

    // Setup JMX
    MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    server.getContainer().addEventListener(mbContainer);
    mbContainer.addBean(statisticsHandler);

    return server;
}
项目:pushrouter    文件:Server.java   
public void run() {
    Runtime.getRuntime().addShutdownHook(new ShutdownHook());
    final AppConfig config = AppConfig.getInstance();

    final int listenerthreads = config.getInt("server.listenerthreads", 2);
    final org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server();
    final SelectChannelConnector connector = new SelectChannelConnector();
    final QueuedThreadPool qtp = new QueuedThreadPool();
    qtp.setName("JettyWorkerPool");
    qtp.setMinThreads(5);
    qtp.setMaxThreads(config.getInt("server.worker", 20));
    connector.setThreadPool(qtp);
    connector.setHost(config.getString("server.bind", "0.0.0.0"));
    connector.setPort(config.getInt("server.port", 8080));
    connector.setMaxIdleTime(120000);
    connector.setLowResourcesMaxIdleTime(60000);
    connector.setLowResourcesConnections(20000);
    connector.setAcceptQueueSize(5000);
    connector.setName("pushrouter");

    server.setConnectors(new Connector[]{(Connector) connector});

    final ServletContextHandler schandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
    schandler.setContextPath("/");

    final ServletHolder cholder = schandler.addServlet("net.zyclonite.pushrouter.StreamServlet", "/stream/*");
    cholder.setInitParameter("listenerthreads", String.valueOf(listenerthreads));
    cholder.setAsyncSupported(true);

    final RequestLogHandler requestLogHandler = new RequestLogHandler();
    if (config.getBoolean("server.accesslogs", false)) {
        final NCSARequestLog requestLog = new NCSARequestLog(config.getString("server.logdir", "./") + "web-yyyy_mm_dd.request.log");
        requestLog.setRetainDays(90);
        requestLog.setAppend(true);
        requestLog.setExtended(false);
        requestLog.setLogTimeZone("GMT");
        requestLogHandler.setRequestLog(requestLog);
    }

    final HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers(new Handler[]{schandler, new DefaultHandler(), requestLogHandler});
    server.setHandler(handlers);

    try {
        server.start();
        LOG.info("PushRouter started");
    } catch (Exception ex) {
        LOG.error("PushRouter could not be started");
    }
}