Redirect Tomcat 7 console log output to a file (Windows)
Asked Answered
U

3

22

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

Underweight answered 28/7, 2011 at 16:55 Comment(0)
S
43

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
Sergei answered 28/7, 2011 at 18:56 Comment(10)
can you give more explanation?? i can't find catalina.bat in tomcat7 :(Deduct
catalina.bat is inside the bin folderSergei
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?Deduct
I am also using tomcat-7.0.26 on the window platform and I can find there are catalina.bat inside the bin folderSergei
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 folderSergei
ohhh my tomcat was installer so why.... now i have downloaded tar :) but what when i use eclipse how pass parameters to tomcat ?Deduct
What does the 2>&1 do?Babs
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?Chromoplast
If you remove 2>&1 it will spit out to both the console and the file (as opposed to only the file)Banderillero
catalina.bat is only in the windows-x64.zip at www-us.apache.org/dist/tomcat/tomcat-7/v7.0.75/bin/… i. It is not in the Tomcat 7 installer at www-us.apache.org/dist/tomcat/tomcat-7/v7.0.75/bin/… 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"Alyosha
S
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.

Saltarello answered 21/1, 2015 at 5:46 Comment(0)
T
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

Towel answered 28/4, 2021 at 4:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.