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()); } }
@Configuration public class WebConfig extends WebMvcConfigurerAdapter implements EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { if (container instanceof TomcatEmbeddedServletContainerFactory) { TomcatEmbeddedServletContainerFactory factory = (TomcatEmbeddedServletContainerFactory) container; AccessLogValve accessLogValve = new Log4JAccessLogValve(); accessLogValve.setDirectory("/var/log/access_log"); accessLogValve.setPattern("%h %u %t "%r" %s %b - %T"); accessLogValve.setSuffix(".log"); factory.addContextValves(accessLogValve); } else { logger.error("WARNING! this customizer does not support a custom configured container"); } } }
protected void setupAccessLogIfNeeds(Context ctx) { if (accessLogOption != null && ctx instanceof StandardContext) { // also check context type just in case final StandardContext stdctx = (StandardContext) ctx; final AccessLogValve valve = new AccessLogValve(); accessLogOption.getLogDir().ifPresent(dir -> valve.setDirectory(dir)); accessLogOption.getFilePrefix().ifPresent(prefix -> valve.setPrefix(prefix)); accessLogOption.getFileSuffix().ifPresent(suffix -> valve.setSuffix(suffix)); accessLogOption.getFileDateFormat().ifPresent(format -> valve.setFileDateFormat(format)); valve.setEncoding(accessLogOption.getFileEncoding().orElse("UTF-8")); valve.setPattern(accessLogOption.getFormatPattern().orElse("common")); accessLogOption.getConditionIf().ifPresent(cond -> valve.setConditionIf(cond)); accessLogOption.getConditionUnless().ifPresent(cond -> valve.setConditionUnless(cond)); stdctx.addValve(valve); } }
accessLogValve.setDirectory(logFile.getAbsolutePath()); String accessLogPattern = ContainerConfig.getPropertyValue(engineConfig, "access-log-pattern", null); if (UtilValidate.isNotEmpty(accessLogPattern)) {
accessLogValve.setBuffered(false); accessLogValve.setCheckExists(true); accessLogValve.setDirectory(dir.getAbsolutePath()); accessLogValve.setRotatable(true); accessLogValve.setRequestAttributesEnabled(true);
alv.setDirectory( new File( extractDirectory, "logs" ).getAbsolutePath() ); alv.setPattern( runtimeProperties.getProperty( Tomcat8Runner.ACCESS_LOG_VALVE_FORMAT_KEY ) ); tomcat.getHost().getPipeline().addValve( alv );
alv.setDirectory( new File( extractDirectory, "logs" ).getAbsolutePath() ); alv.setPattern( runtimeProperties.getProperty( Tomcat7Runner.ACCESS_LOG_VALVE_FORMAT_KEY ) ); tomcat.getHost().getPipeline().addValve( alv );
alv.setDirectory( new File( extractDirectory, "logs" ).getAbsolutePath() ); alv.setPattern( runtimeProperties.getProperty( Tomcat7Runner.ACCESS_LOG_VALVE_FORMAT_KEY ) ); tomcat.getHost().getPipeline().addValve( alv );
alv.setDirectory( new File( configurationDir, "logs" ).getAbsolutePath() ); alv.setPattern( "%h %l %u %t \"%r\" %s %b %I %D" ); embeddedTomcat.getHost().getPipeline().addValve( alv );
alv.setDirectory( new File( configurationDir, "logs" ).getAbsolutePath() ); alv.setPattern( "%h %l %u %t \"%r\" %s %b %I %D" ); embeddedTomcat.getHost().getPipeline().addValve( alv );