Search code examples
javalinuxspring-boottomcatcatalina

how to link catalina.out file with embedded tomcat


I've stumbled upon this issue which seems to be trivial and yet I do not know from which side I should approach it.

I've packaged a jar spring boot application and placed it on my CentOs server and started it as a Systemd service with a startup script. The question is this: How do I tell the embedded tomcat to point to his specific catalina.out file that I've created somewhere and to write logs there. I've been thinking in two directions. One is programmatically tell embedded tomcat where the catalina.out is from my code where i instantiate connectors etc., second is to tell systemd script where the catalina.out is located. But i can not find anything on the web regarding this issue.

EDIT My embedded tomcat current configuration

@Bean 
      EmbeddedServletContainerCustomizer containerCustomizer() throws Exception {
            System.out.println("TOMCAT CALLED");
          return (ConfigurableEmbeddedServletContainer container) -> {

              if (container instanceof TomcatEmbeddedServletContainerFactory) {

                  TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;

                  tomcat.addConnectorCustomizers(
                          (connector) -> {
                              connector.setPort(9595);
                              connector.setRedirectPort(9444);
                              connector.setAttribute("address", "127.0.0.1");
                              //connector.setPr
                              Http11NioProtocol proto = (Http11NioProtocol) connector.getProtocolHandler();
                              proto.setConnectionTimeout(20000);

                              System.out.println("apr available: "+AprLifecycleListener.isAprAvailable());

                          }
                  );
              }
          };
      }

Any help would be much appreciated! Thanks.


Solution

  • Just set logging.file=/location/of/catalina.out in your application.properties. You can refer to Spring Boot logging documentation for more: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html