2012/7/16 Benjamin Muschko <benjamin.musc...@gmail.com>: > Hi, > > I'd like to redirect the embedded Tomcat's startup logging messages to a > file. What I am looking for is something like this: > > ... > Initializing ProtocolHandler ["http-bio-8080"] > Initializing ProtocolHandler ["http-bio-8091"] > Starting service Tomcat > Starting Servlet Engine: Apache Tomcat/7.0.11 > ... > > So far I haven't found a way of making this work. My first approach was to > add a FileHandler to the context's logger: > > Handler fh = new FileHandler("output.log", true); > fh.formatter = new SimpleFormatter(); > fh.level = Level.ALL; > fh.encoding = "UTF-8"; > context.getLogger().logger.addHandler(fh); > > It works fine for the context in Tomcat 7 but doesn't give me the result I > am looking for.
context.getLogger() returns logger for certain named log category only. As a coincidence, it is the same one as used by log methods in Servlet API. Other Tomcat components use other log categories (aka logger names). > Also trying to capture System.out and System.err and > writing it to a file doesn't solve my problem: > > System.setOut(new PrintStream(new File("output-file.txt"))); > System.setErr(new PrintStream(new File("output-file.txt"))); > If java.util.logging starts before you run the above code, it can create a ConsoleHandler using original stderr and stdout. Your setOut() and setErr() will have no influence on it. > I guess I am not clear on how the embedded Tomcat implementation logs the > messages to the console and how I can change it. java.util.logging.ConsoleHandler for the default log category writes messages to the console. If none were configured, nothing were printed there. See java.util.logging documentation in JDK. Essentially its bootstrap is controlled via certain system properties when your java application (the one that embeds Tomcat) starts. > Could somebody clarify this > for me. It would be great to see and example that would work for embedded > Tomcat 6 & 7. > Best regards, Konstantin Kolinko --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org