how to redirect the system.out.println messages of a servlet in a log


When I run a servlet from eclipse (with eclipse controlling tomcat) I see the system.out.println output in eclipse console. But when I run it outside of eclipse then where do these messages get written to.

How can I get this output to some logs of tomcat

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

it should be in the tomcat logs.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jim CakalicSenior Developer/ArchitectCommented:
Console output (System.out/err) is usually redirected to the file named catalina.out. The name is configurable using an environment variable. (See the startup scripts.)
Jim CakalicSenior Developer/ArchitectCommented:
I should have mentioned previously that you want to minimize (preferably eliminate) the use of System.out and System.err calls in your servlet code. IBM's WebSphere Best Practices whitepaper recommends this citing a throughput study that showed a servlet reduction in throughput from 70+ requests per second to 10 when the servlet contained just one System.out.println. While the whitepaper is fairly old (2000) the reason this is a best practice hasn't changed -- System.out/err calls are synchronized on a global resource that blocks other threads for duration of disk I/O.

WebSphere Application Server Development Best Practices for Performance and Scalability

anshumaEngineeringAuthor Commented:
so what's the best way to get everything recorded somewhere. Will log4j help here, I want to make sure that it's easier to trace back errors in production
Jim CakalicSenior Developer/ArchitectCommented:
Yes. A logging framework would be better than direct System.out/err, particularly if it permits you to log asynchronously so that your request processing thread isn't blocked on file I/O

See (particularly the performance comparisons at the 2nd link)
Logback Performance Tweaks
Asynchronous Loggers for Low-Latency Logging
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.