How do I view tomcat's method of console output

  • 2020-09-16 07:51:48
  • OfStack

During the debugging of web project, it is often necessary to check the debugging information output. For example, when Hibernate is set to display SQL statement, each run of SQL statement will be output to the terminal. In addition, sometimes 1 output statement needs to be inserted into the code to facilitate the operation, but when System.out. When such a console outputs a statement, it is not directly visible at the terminal.

In tomcat, the terminal output information is output to


$CATALINA_HOME/logs/catalina.out 

Where $CATALINA_HOME is the installation directory for tomcat.

When tomcat is started, the file is updated once per second and logs are entered into it, so viewing the contents of the file directly open is often difficult because the file is constantly being refreshed. We want to see dynamic log content in two ways:

1. 1

Go to the bin directory in the tomcat installation path and run the sh catalina.sh run command to display the contents of catalina.out dynamically on the terminal

2. 2

Go to the logs directory under the above installation directory and execute the following command


tail -f catalina.out 

Tomcat console log output to a file method

startup. bat modify

call "%EXECUTABLE%" start %CMD_LINE_ARGS%

for

call "%EXECUTABLE%" run %CMD_LINE_ARGS% ( > > ..\logs\detailLog.%DATE:~0,10%.log )

So the console won't output the log files, let catalina.bat decide where to put the log output

In ES69en.bat, look for 4 places ending in %ACTION%, and add each place after %ACTION% > > ..\logs\detailLog.%DATE:~0,10%.log

detailLog is my name, so you can change it, but be careful not to clash with the default log file, or you will get an error. The %DATE:~0,10% is used to intercept the system time (note the time format problem generated by the system here, if it is 2013/04/02, an error will occur, please make sure the system time format). On my server, echo %DATE% shows "2013-04-02", intercept 0-10 bits, that is, "2013-04-02", so the name of the log file generated today should be detailLog.2013-04-02.log

If you double-click startup.bat again, you will find that the console will no longer output the log file after starting. If you check detailLog.2013-04-02.log, you will find the log in it. The following work is how to simply display the log file.

Change the system date format in

Date and Time Settings in the lower right corner of the desktop - Change calendar Settings - Short dates in date format under the Date TAB drop down select box to modify

Download UnxUtils https: / / sourceforge net/projects/unxutils /

Unzip UnxUtils\usr\local\wbin to the system environment variable Path

Open cmd and type tail --help


Related articles: