Hi. I am running a servlet on tomcat 6. I want to redirect System.out.println and System.out.err messages from the tomcat console into a file in the "webapps" folder. This is coz i am running my servlet on my school's tomcat server where I have access to only the webapps folder. I have tomcat installed on my laptop and when i redirect the console output using System.setOut and System.setErr into a text file, the text file is generated in the bin folder. Hence I gave a relative path to webapps folder from bin folder. This works fine on the tomcat on my laptop but does not work on my school's server. I am not able to view any other folder than the webapps due to security restrictions on the school server. Please help me with a work around
I'm guessing your main goal here is not outputting anything BUT to get log files so that you can debug your application. Am I correct? If that is the case then one workaround is to discard all your efforts to that direction and use some ready logging mechanism. Like log4j http://logging.apache.org/log4j/1.2/download.html
Altought it takes some time to get yourself familiar with it and learning how to configure it, it pays off in the end. And once you know how to do it you can copy the configuration to all your future projects as well and so on...
You could also look for some code online to intercept the system output and save it to someplace. But it's kind of shaky if you had only webapps directory to put the file. You probably don't want to reside it right under webapps. And if you put it under your application's, say log or tmp directory, you may have problem to re-deploy your application -- I had done that before. I was not able to un-deploy the application successfully because the log file was open.
Good luck. Ben
Joined: Jun 30, 2008
Hi Ben and Ilari,
Thank you for your suggestions. Ilari I have downloaded log4j. Thank you. Meanwhile I have tried Ben's suggestion and it works. Thank you.
hey sandeep . yar if you have done this meanz redirected your console output to the .txt file then plase do tell me i am doing the same thing but unfortunatly failed because i have no idea how to use log4j so please help me . because i got stuck in my final project.