SoFunction
Updated on 2025-03-08

How to view the console output of tomcat

During web project debugging, you often need to view the output debugging information. For example, when Hibernate is set to display SQL statements, each time the SQL statement run will be output to the terminal. In addition, sometimes some output statements need to be inserted into the code to facilitate the operation, but when inserting such a console output statement, it cannot be seen directly in the terminal.

In tomcat, the terminal output information is output to

$CATALINA_HOME/logs/ 

where $CATALINA_HOME is the installation directory of tomcat.

After tomcat is started, the file will be updated once every second, and log information is entered in it. Therefore, if you view the file contents by directly opening it, it is often difficult to achieve because the file is constantly refreshing. We want to view dynamic log content in two ways:

1. Method one

Enter the bin directory of the tomcat installation path, run the sh run command, and the contents will be displayed dynamically in the terminal

2. Method 2

Enter the logs directory under the above installation directory and execute the following command

tail -f  

How to output Tomcat console logs to files

Modified

call "%EXECUTABLE%" start %CMD_LINE_ARGS%

for

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

In this way, the console will not output the log file, let's decide where the log output is

Look for four places ending with %ACTION% and add each %ACTION% after   >> ..\logs\detailLog.%DATE:~0,10%.log

detailLog is my own name, you can change it at will, but be careful not to conflict with the default log file, otherwise an error will be reported when starting. Then %DATE: ~0, 10% is used to intercept the system time (you should pay attention to the time format problem generated by the system here. If it is 2013/04/02, an error will occur. Please ensure the system time format). On my server, echo %DATE% shows "2013-04-02 Tuesday", which intercepts 0-10 bits, which is "2013-04-02", so the name of the log file generated today should be detailedLog.

Double-click this again and you will find that the console will no longer output log files after it is started. Go to check the detailLog. and you will find that the logs are all inside. 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 date drop-down selection box under Date format under Date tab Modify

Download UnxUtils/projects/unxutils/

Decompress and add UnxUtils\usr\local\wbin to the system environment variable Path

Open cmd and enter tail --help

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.