简体   繁体   中英

How does Tomcat redirect verbose:gc console output to catalina.out

I need to understand how Tomcat is able to catch JVM garbage collection console output logs and put it in catalina.out.

I tried to redirect System.out and System.err , but no can do. I was not able to get the output of GC logs.
However, when activating -verbose:gc in Tomcat (in catalina.sh, *JAVA_OPT*) and later cheking the output in catalina.out I was able to see the GC logs. How is this possible? How was Tomcat able to redirect that output to a file?

Maybe do you know any way to redirect the GC log output inside some java application using java code?

Thank you in advance.

It has nothing to do with code; the catalina.out file is not a "real log", it's just a file into which the standard tomcat startup command pushes all it's output.

In other words, this is a shell question, not a java one :)

Tomcat must indeed be using System.setErr() and System.setOut(). There's a great discussion about how that works elsewhere on this site: java: "final" System.out, System.in and System.err?

Tomcat redirects all console output to catalina.out. You might be able to configure this via the JULI log settings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM