I have a web app in Spring Boot that can take a war file and deploy it with embedded tomcat 8. So, for each uploaded war file I do the following
Tomcat tomcat = new Tomcat();
tomcat.setPort(port);
File catalinaHome = new File(TOMCAT_DIR + port);
catalinaHome.mkdirs();
File webapp = new File(TOMCAT_DIR + port + "\\webapps");
webapp.mkdir();
tomcat.setBaseDir(catalinaHome.getAbsolutePath());
try {
File war = new File("myapp.war");
StandardContext context = (StandardContext) tomcat.addWebapp("/myapp", war.getAbsolutePath());
context.setAntiResourceLocking(true);
tomcat.start();
} catch (Exception e) {
e.printStackTrace();
}
I don't have any idea how can I redirect the output.
I read that tomcat embedded log to System.out
, and I was able to redirect to file with:
PrintStream out = new PrintStream(new FileOutputStream("output.txt"));
System.setOut(out);
but redirect all output, and I want something that log to a different file for each tomcat instance that I run. Any solution that I found so far don't resolve my problem. Thanks