org.apache.catalina.valves.AccessLogValve Java Examples

The following examples show how to use org.apache.catalina.valves.AccessLogValve. 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: TomcatApplication.java    From micro-server with Apache License 2.0 6 votes vote down vote up
private void addAccessLog(Tomcat httpServer, StandardContext context) {
	try {

		String accessLogLocation = serverData.getRootContext().getBean(AccessLogLocationBean.class).getAccessLogLocation();

		accessLogLocation = accessLogLocation + "/" + replaceSlash(serverData.getModule().getContext()) + "-access.log";

		AccessLogValve accessLogValve = new AccessLogValve();
           accessLogValve.setDirectory(accessLogLocation);
           accessLogValve.setPattern(Constants.AccessLog.COMMON_ALIAS);
           accessLogValve.setSuffix(".log");
           accessLogValve.setRotatable(true);
           context.getPipeline().addValve(accessLogValve);

	} catch (Exception e) {

		logger.error(InternalErrorCode.SERVER_STARTUP_FAILED_TO_CREATE_ACCESS_LOG.toString() + ": " + e.getMessage());
		if (e.getCause() != null)
			logger.error("CAUSED BY: " + InternalErrorCode.SERVER_STARTUP_FAILED_TO_CREATE_ACCESS_LOG.toString() + ": " + e.getCause().getMessage());

	}

}
 
Example #2
Source File: AccessLogBenchmark.java    From tomcat-mongo-access-log with Apache License 2.0 6 votes vote down vote up
@Override
public void setUpValve(Tomcat tomcat) {
  // clear AccessLogValve
  for (Valve vl : tomcat.getHost().getPipeline().getValves()) {
    if (vl.getClass().equals(AccessLogValve.class)) {
      tomcat.getHost().getPipeline().removeValve(vl);
    }
  }
  
  if (accessLogDirectory == null) {
    accessLogDirectory = new File(getBuildDirectory(), "logs").toString();
  }
  AccessLogValve alv = new AccessLogValve();
  alv.setDirectory(accessLogDirectory);
  alv.setPattern("combined");

  tomcat.getHost().getPipeline().addValve(alv);
}
 
Example #3
Source File: MongoLogBenchmark.java    From tomcat-mongo-access-log with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUpValve(Tomcat tomcat) throws UnknownHostException {
  // remove AccessLogValve
  for (Valve vl : tomcat.getHost().getPipeline().getValves()) {
    if (vl.getClass().equals(AccessLogValve.class)) {
      tomcat.getHost().getPipeline().removeValve(vl);
    }
  }
  
  mongoClient = new MongoClient(new MongoClientURI(url));
  db = mongoClient.getDB(dbName);
  
  MongoAccessLogValve mavl = new MongoAccessLogValve();
  mavl.setUri(url);
  mavl.setDbName(dbName);
  mavl.setCollName(collName);
  mavl.setPattern(pattern);
  
  tomcat.getHost().getPipeline().addValve(mavl);
}
 
Example #4
Source File: TomcatWebServer.java    From oxygen with Apache License 2.0 5 votes vote down vote up
private void configEngine(Engine engine, TomcatConf tomcatConf) {
  engine.setBackgroundProcessorDelay(tomcatConf.getBackgroundProcessorDelay());
  if (tomcatConf.isAccessLogEnabled()) {
    AccessLogValve value = new AccessLogValve();
    value.setBuffered(tomcatConf.isAccessLogBuffered());
    value.setFileDateFormat(tomcatConf.getAccessLogFileFormat());
    value.setRequestAttributesEnabled(tomcatConf.isAccessLogRequestAttributesEnabled());
    value.setPattern(tomcatConf.getAccessLogPattern());
    engine.getPipeline().addValve(value);
  }

}
 
Example #5
Source File: MBeanFactory.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new AccessLoggerValve.
 *
 * @param parent MBean Name of the associated parent component
 *
 * @exception Exception if an MBean cannot be created or registered
 *
 * @deprecated  Will be removed in Tomcat 8.0.x. Replaced by {@link
 *              #createValve(String, String)}.
 */
@Deprecated
public String createAccessLoggerValve(String parent)
    throws Exception {

    ObjectName pname = new ObjectName(parent);
    // Create a new AccessLogValve instance
    AccessLogValve accessLogger = new AccessLogValve();
    ContainerBase containerBase = getParentContainerFromParent(pname);
    // Add the new instance to its parent component
    containerBase.getPipeline().addValve(accessLogger);
    ObjectName oname = accessLogger.getObjectName();
    return (oname.toString());

}
 
Example #6
Source File: MBeanFactory.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new AccessLoggerValve.
 *
 * @param parent MBean Name of the associated parent component
 *
 * @exception Exception if an MBean cannot be created or registered
 *
 * @deprecated  Will be removed in Tomcat 8.0.x. Replaced by {@link
 *              #createValve(String, String)}.
 */
@Deprecated
public String createAccessLoggerValve(String parent)
    throws Exception {

    ObjectName pname = new ObjectName(parent);
    // Create a new AccessLogValve instance
    AccessLogValve accessLogger = new AccessLogValve();
    ContainerBase containerBase = getParentContainerFromParent(pname);
    // Add the new instance to its parent component
    containerBase.getPipeline().addValve(accessLogger);
    ObjectName oname = accessLogger.getObjectName();
    return (oname.toString());

}
 
Example #7
Source File: TomcatBaseTest.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Before
@Override
public void setUp() throws Exception {
    super.setUp();

    // Trigger loading of catalina.properties
    CatalinaProperties.getProperty("foo");

    File appBase = new File(getTemporaryDirectory(), "webapps");
    if (!appBase.exists() && !appBase.mkdir()) {
        Assert.fail("Unable to create appBase for test");
    }

    tomcat = new TomcatWithFastSessionIDs();

    String protocol = getProtocol();
    Connector connector = new Connector(protocol);
    // Listen only on localhost
    connector.setAttribute("address",
            InetAddress.getByName("localhost").getHostAddress());
    // Use random free port
    connector.setPort(0);
    // Mainly set to reduce timeouts during async tests
    connector.setAttribute("connectionTimeout", "3000");
    tomcat.getService().addConnector(connector);
    tomcat.setConnector(connector);

    // Add AprLifecycleListener if we are using the Apr connector
    if (protocol.contains("Apr")) {
        StandardServer server = (StandardServer) tomcat.getServer();
        AprLifecycleListener listener = new AprLifecycleListener();
        listener.setSSLRandomSeed("/dev/urandom");
        server.addLifecycleListener(listener);
        connector.setAttribute("pollerThreadCount", Integer.valueOf(1));
    }

    File catalinaBase = getTemporaryDirectory();
    tomcat.setBaseDir(catalinaBase.getAbsolutePath());
    tomcat.getHost().setAppBase(appBase.getAbsolutePath());

    accessLogEnabled = Boolean.parseBoolean(
        System.getProperty("tomcat.test.accesslog", "false"));
    if (accessLogEnabled) {
        String accessLogDirectory = System
                .getProperty("tomcat.test.reports");
        if (accessLogDirectory == null) {
            accessLogDirectory = new File(getBuildDirectory(), "logs")
                    .toString();
        }
        AccessLogValve alv = new AccessLogValve();
        alv.setDirectory(accessLogDirectory);
        alv.setPattern("%h %l %u %t \"%r\" %s %b %I %D");
        tomcat.getHost().getPipeline().addValve(alv);
    }

    // Cannot delete the whole tempDir, because logs are there,
    // but delete known subdirectories of it.
    addDeleteOnTearDown(new File(catalinaBase, "webapps"));
    addDeleteOnTearDown(new File(catalinaBase, "work"));
}
 
Example #8
Source File: TomcatBaseTest.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@Before
@Override
public void setUp() throws Exception {
    super.setUp();

    // Trigger loading of catalina.properties
    CatalinaProperties.getProperty("foo");

    File appBase = new File(getTemporaryDirectory(), "webapps");
    if (!appBase.exists() && !appBase.mkdir()) {
        fail("Unable to create appBase for test");
    }

    tomcat = new TomcatWithFastSessionIDs();

    String protocol = getProtocol();
    Connector connector = new Connector(protocol);
    // Listen only on localhost
    connector.setAttribute("address",
            InetAddress.getByName("localhost").getHostAddress());
    // Use random free port
    connector.setPort(0);
    // Mainly set to reduce timeouts during async tests
    connector.setAttribute("connectionTimeout", "3000");
    tomcat.getService().addConnector(connector);
    tomcat.setConnector(connector);

    // Add AprLifecycleListener if we are using the Apr connector
    if (protocol.contains("Apr")) {
        StandardServer server = (StandardServer) tomcat.getServer();
        AprLifecycleListener listener = new AprLifecycleListener();
        listener.setSSLRandomSeed("/dev/urandom");
        server.addLifecycleListener(listener);
        connector.setAttribute("pollerThreadCount", Integer.valueOf(1));
    }

    File catalinaBase = getTemporaryDirectory();
    tomcat.setBaseDir(catalinaBase.getAbsolutePath());
    tomcat.getHost().setAppBase(appBase.getAbsolutePath());

    accessLogEnabled = Boolean.parseBoolean(
        System.getProperty("tomcat.test.accesslog", "false"));
    if (accessLogEnabled) {
        String accessLogDirectory = System
                .getProperty("tomcat.test.reports");
        if (accessLogDirectory == null) {
            accessLogDirectory = new File(getBuildDirectory(), "logs")
                    .toString();
        }
        AccessLogValve alv = new AccessLogValve();
        alv.setDirectory(accessLogDirectory);
        alv.setPattern("%h %l %u %t \"%r\" %s %b %I %D");
        tomcat.getHost().getPipeline().addValve(alv);
    }

    // Cannot delete the whole tempDir, because logs are there,
    // but delete known subdirectories of it.
    addDeleteOnTearDown(new File(catalinaBase, "webapps"));
    addDeleteOnTearDown(new File(catalinaBase, "work"));
}
 
Example #9
Source File: TomcatBaseTest.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Before
@Override
public void setUp() throws Exception {
    super.setUp();

    // Trigger loading of catalina.properties
    CatalinaProperties.getProperty("foo");

    File appBase = new File(getTemporaryDirectory(), "webapps");
    if (!appBase.exists() && !appBase.mkdir()) {
        fail("Unable to create appBase for test");
    }

    tomcat = new TomcatWithFastSessionIDs();

    String protocol = getProtocol();
    Connector connector = new Connector(protocol);
    // Listen only on localhost
    connector.setAttribute("address",
            InetAddress.getByName("localhost").getHostAddress());
    // Use random free port
    connector.setPort(0);
    // Mainly set to reduce timeouts during async tests
    connector.setAttribute("connectionTimeout", "3000");
    tomcat.getService().addConnector(connector);
    tomcat.setConnector(connector);

    // Add AprLifecycleListener if we are using the Apr connector
    if (protocol.contains("Apr")) {
        StandardServer server = (StandardServer) tomcat.getServer();
        AprLifecycleListener listener = new AprLifecycleListener();
        listener.setSSLRandomSeed("/dev/urandom");
        server.addLifecycleListener(listener);
        connector.setAttribute("pollerThreadCount", Integer.valueOf(1));
    }

    File catalinaBase = getTemporaryDirectory();
    tomcat.setBaseDir(catalinaBase.getAbsolutePath());
    tomcat.getHost().setAppBase(appBase.getAbsolutePath());

    accessLogEnabled = Boolean.parseBoolean(
        System.getProperty("tomcat.test.accesslog", "false"));
    if (accessLogEnabled) {
        String accessLogDirectory = System
                .getProperty("tomcat.test.reports");
        if (accessLogDirectory == null) {
            accessLogDirectory = new File(getBuildDirectory(), "logs")
                    .toString();
        }
        AccessLogValve alv = new AccessLogValve();
        alv.setDirectory(accessLogDirectory);
        alv.setPattern("%h %l %u %t \"%r\" %s %b %I %D");
        tomcat.getHost().getPipeline().addValve(alv);
    }

    // Cannot delete the whole tempDir, because logs are there,
    // but delete known subdirectories of it.
    addDeleteOnTearDown(new File(catalinaBase, "webapps"));
    addDeleteOnTearDown(new File(catalinaBase, "work"));
}
 
Example #10
Source File: TomcatBaseTest.java    From tomcat-mongo-access-log with Apache License 2.0 4 votes vote down vote up
@Before
@Override
public void setUp() throws Exception {
    super.setUp();

    // Trigger loading of catalina.properties
    CatalinaProperties.getProperty("foo");

    File appBase = new File(getTemporaryDirectory(), "webapps");
    if (!appBase.exists() && !appBase.mkdir()) {
        fail("Unable to create appBase for test");
    }

    tomcat = new TomcatWithFastSessionIDs();

    String protocol = getProtocol();
    Connector connector = new Connector(protocol);
    // Listen only on localhost
    connector.setAttribute("address",
            InetAddress.getByName("localhost").getHostAddress());
    // Use random free port
    connector.setPort(0);
    // Mainly set to reduce timeouts during async tests
    connector.setAttribute("connectionTimeout", "3000");
    tomcat.getService().addConnector(connector);
    tomcat.setConnector(connector);

    // Add AprLifecycleListener if we are using the Apr connector
    if (protocol.contains("Apr")) {
        StandardServer server = (StandardServer) tomcat.getServer();
        AprLifecycleListener listener = new AprLifecycleListener();
        listener.setSSLRandomSeed("/dev/urandom");
        server.addLifecycleListener(listener);
        connector.setAttribute("pollerThreadCount", Integer.valueOf(1));
    }

    File catalinaBase = getTemporaryDirectory();
    tomcat.setBaseDir(catalinaBase.getAbsolutePath());
    tomcat.getHost().setAppBase(appBase.getAbsolutePath());

    accessLogEnabled = Boolean.parseBoolean(
        System.getProperty("tomcat.test.accesslog", "false"));
    if (accessLogEnabled) {
        String accessLogDirectory = System
                .getProperty("tomcat.test.reports");
        if (accessLogDirectory == null) {
            accessLogDirectory = new File(getBuildDirectory(), "logs")
                    .toString();
        }
        AccessLogValve alv = new AccessLogValve();
        alv.setDirectory(accessLogDirectory);
        alv.setPattern("%h %l %u %t \"%r\" %s %b %I %D");
        tomcat.getHost().getPipeline().addValve(alv);
    }

    // Cannot delete the whole tempDir, because logs are there,
    // but delete known subdirectories of it.
    addDeleteOnTearDown(new File(catalinaBase, "webapps"));
    addDeleteOnTearDown(new File(catalinaBase, "work"));
}