0

When I deploy my war file on a standalone tomcat server and start tomcat using startup.bat script, All my System.out.println show up on the tomcat console and since there is lot of information they quickly refresh and I cant read them.

I don't see those statements in any of the tomcat log files. Is there a way to have them printed in log files(when tomcat console is open as well)? Looks like all that information gets printed on tomcat and never goes to the log files.

user1892775
  • 2,001
  • 6
  • 37
  • 58

1 Answers1

1

System.out.println isn't a good idea. Your experience is correct: Those records are written to the console. That's not helpful if you don't have access to the server.

A better solution is to use log4j or its successor, slf4j.

I wonder if this could be a solution for you.

Community
  • 1
  • 1
duffymo
  • 305,152
  • 44
  • 369
  • 561
  • Where do the debugs for this go? System.setProperty("javax.net.debug","all"); – user1892775 Aug 27 '15 at 17:12
  • Where you tell it. You can set up a rolling log file appender in log4j; warn, info, error, and debug levels are written to that file. – duffymo Aug 27 '15 at 17:13
  • They go to the log appender configured in the properties file, which may be a file, the console, or perhaps a database. The choice, is yours, you can control which classes will be captured by which appenders and at what level. – Gavin Aug 27 '15 at 17:13
  • 1
    You don't use system properties to accomplish this. People don't usually get to touch the app server on which their stuff deploys and runs. – duffymo Aug 27 '15 at 17:13
  • I would suggest log4j.properties, or the more modern Java configuration route – Gavin Aug 27 '15 at 17:14
  • No one that I know of uses .properties; .xml is ubiquitous. – duffymo Aug 27 '15 at 17:15
  • @duffymo the article you mentioned did the trick of moving the output to a log file. Thanks for that. The only other thing that I am still not sure about is how to view the output from System.setProperty("javax.net.debug","all"); when using tomcat – user1892775 Aug 27 '15 at 17:31
  • When I run a standalone Java program with this property set, I can see all the debugs. But when running a webapp with tomcat, I am just not sure where it goes. So, where does it go by default? And if they dont go anywhere by default, how exactly I can configure it to print it to a log file etc. Perhaps, if you can point me to an article that explains in detail? I have a piece of code that works fine as a standalone program but not when executing in webapp, so the debug output from the above property would be really useful for me – user1892775 Aug 27 '15 at 17:32
  • You need to modify your code - replace System.out.println with Log4j logging statements. – duffymo Aug 27 '15 at 18:20