Java Code Examples for org.eclipse.jetty.server.NCSARequestLog#setLogTimeZone()

The following examples show how to use org.eclipse.jetty.server.NCSARequestLog#setLogTimeZone() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MinimalServletsWithLogging.java    From cs601 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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();
}
 
Example 2
Source File: ServerDaemon.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 3
Source File: JettyStarter.java    From scheduling with GNU Affero General Public License v3.0 4 votes vote down vote up
public List<String> deployWebApplications(String rmUrl, String schedulerUrl) {
    initializeRestProperties();

    setSystemPropertyIfNotDefined("rm.url", rmUrl);
    setSystemPropertyIfNotDefined("scheduler.url", schedulerUrl);

    if (WebProperties.WEB_DEPLOY.getValueAsBoolean()) {
        logger.info("Starting the web applications...");

        int httpPort = getJettyHttpPort();
        int httpsPort = 443;
        if (WebProperties.WEB_HTTPS_PORT.isSet()) {
            httpsPort = WebProperties.WEB_HTTPS_PORT.getValueAsInt();
        }

        boolean httpsEnabled = WebProperties.WEB_HTTPS.getValueAsBoolean();
        boolean redirectHttpToHttps = WebProperties.WEB_REDIRECT_HTTP_TO_HTTPS.getValueAsBoolean();

        int restPort = httpPort;

        String httpProtocol;
        String[] defaultVirtualHost;
        String[] httpVirtualHost = new String[] { "@" + HTTP_CONNECTOR_NAME };

        if (httpsEnabled) {
            httpProtocol = "https";
            defaultVirtualHost = new String[] { "@" + HTTPS_CONNECTOR_NAME };
            restPort = httpsPort;
        } else {
            defaultVirtualHost = httpVirtualHost;
            httpProtocol = "http";
        }

        Server server = createHttpServer(httpPort, httpsPort, httpsEnabled, redirectHttpToHttps);

        server.setStopAtShutdown(true);

        HandlerList handlerList = new HandlerList();

        if (WebProperties.JETTY_LOG_FILE.isSet()) {
            String pathToJettyLogFile = FileStorageSupportFactory.relativeToHomeIfNotAbsolute(WebProperties.JETTY_LOG_FILE.getValueAsString());
            File jettyLogFile = new File(pathToJettyLogFile);
            if (!jettyLogFile.getParentFile().exists() && !jettyLogFile.getParentFile().mkdirs()) {
                logger.error("Could not create jetty log file in: " +
                             WebProperties.JETTY_LOG_FILE.getValueAsString());
            } else {
                NCSARequestLog requestLog = new NCSARequestLog(pathToJettyLogFile);
                requestLog.setAppend(true);
                requestLog.setExtended(false);
                requestLog.setLogTimeZone("GMT");
                requestLog.setLogLatency(true);
                requestLog.setRetainDays(WebProperties.JETTY_LOG_RETAIN_DAYS.getValueAsInt());

                RequestLogHandler requestLogHandler = new RequestLogHandler();
                requestLogHandler.setRequestLog(requestLog);
                handlerList.addHandler(requestLogHandler);
            }
        }

        if (httpsEnabled && redirectHttpToHttps) {
            ContextHandler redirectHandler = new ContextHandler();
            redirectHandler.setContextPath("/");
            redirectHandler.setHandler(new SecuredRedirectHandler());
            redirectHandler.setVirtualHosts(httpVirtualHost);
            handlerList.addHandler(redirectHandler);
        }

        addWarsToHandlerList(handlerList, defaultVirtualHost);
        server.setHandler(handlerList);

        String schedulerHost = ProActiveInet.getInstance().getHostname();
        return startServer(server, schedulerHost, restPort, httpProtocol);
    }
    return new ArrayList<>();
}