tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benjamin Muschko <benjamin.musc...@gmail.com>
Subject Embedded Tomcat 6 & 7 logging to file
Date Sun, 15 Jul 2012 22:57:11 GMT
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.  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")));

I guess I am not clear on how the embedded Tomcat implementation logs the
messages to the console and how I can change it. Could somebody clarify this
for me. It would be great to see and example that would work for embedded
Tomcat 6 & 7.

Thanks,

Ben

--
View this message in context: http://tomcat.10.n6.nabble.com/Embedded-Tomcat-6-7-logging-to-file-tp4984104.html
Sent from the Tomcat - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message