22

How do I redirect Tomcat 7 console log output to a file on Windows?

Justin Kredible
  • 8,354
  • 15
  • 65
  • 91

3 Answers3

44

Using catalina.bat run can start the tomcat in the current console instead of a new console , so you can redirect all the standard error and standard output stream of this command to a file using

catalina.bat run > tomcat.log 2>&1
Ken Chan
  • 84,777
  • 26
  • 143
  • 172
  • can you give more explanation?? i can't find catalina.bat in tomcat7 :( – Ankur Loriya Mar 13 '12 at 06:32
  • `catalina.bat` is inside the `bin` folder – Ken Chan Mar 13 '12 at 13:26
  • i am using Tomcat 7 so there is no any bat file in bin folder... is there any other way to redirect sysout to log file? – Ankur Loriya Mar 21 '12 at 05:37
  • I am also using tomcat-7.0.26 on the window platform and I can find there are `catalina.bat` inside the `bin` folder – Ken Chan Mar 21 '12 at 06:19
  • I don't know why you have one bat file in your tomcat7 , I just downloaded the latest version of tomcat (7.0.26) for windows from the official site and there are totally 9 bat files in the bin folder – Ken Chan Mar 21 '12 at 07:38
  • ohhh my tomcat was installer so why.... now i have downloaded tar :) but what when i use eclipse how pass parameters to tomcat ? – Ankur Loriya Mar 22 '12 at 09:31
  • 10
    What does the 2>&1 do? – jewbix.cube Feb 27 '14 at 02:32
  • This works. But is there a way to limit file size of the tomcat.log in this case and create a new file once this limit is reached or maybe per day basis? – Mukul Goel Feb 09 '15 at 14:31
  • 1
    If you remove 2>&1 it will spit out to both the console and the file (as opposed to only the file) – developer747 Feb 09 '15 at 20:28
  • catalina.bat is only in the windows-x64.zip at http://www-us.apache.org/dist/tomcat/tomcat-7/v7.0.75/bin/apache-tomcat-7.0.75-windows-x64.zip i. It is not in the Tomcat 7 installer at http://www-us.apache.org/dist/tomcat/tomcat-7/v7.0.75/bin/apache-tomcat-7.0.75.exe If you want extra debug info make a file called setenv.bat and put it in the bin DIR and add this line: set "JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8100 -verbose:class" – technocrusaders.com Mar 08 '17 at 21:18
6

To get the Tomcat output and share it:: 1. Make a file " Start_Tomcat.bat " put the below lines in that.

cd C:\XXX\apache-tomcat-6.0.20\bin
        catalina.bat run > C:\XXX\apache-tomcat-6.0.20\logs\tomcat1.log 2>&1

NOTES:: C:\XXX\apache-tomcat-6.0.20\bin -- is the systems bin address " \logs\tomcat1.log 2>&1 " should not change...

    Ques:: What does the 2>&1 do?
    Ans:: 2>&1 means output only to file. Without that it would output to both text and console.
  1. Paste the file in the below location::: " C:\XXX\apache-tomcat-6.0.20\bin "

  2. Run " Startup.bat " & " Start_Tomcat.bat "

  3. You will get " C:\XXX\apache-tomcat-6.0.20\logs\tomcat1.log " . Share the "tomcat1.log" file so others can see your tomcat responses.

P S M
  • 1,121
  • 12
  • 29
0

File: catalina.bat (in the Tomcat's root \bin directory)

Lines:

rem Comment out the line below
rem set _EXECJAVA=start "%TITLE%" %_RUNJAVA%
rem Add the line below instead
set _EXECJAVA=%_RUNJAVA%

Next, find the line making the final Java call (add the redirection as below):

%_EXECJAVA% %CATALINA_LOGGING_CONFIG% %LOGGING_MANAGER% ... 2>&1 >c:\temp\tomcat.log

You will then get your stdout and stderr streams in the file c:\temp\tomcat.log

access_granted
  • 1,807
  • 20
  • 25