Use commands to dynamically output tomcat logs under windows

There are two testers in the project, who often need to check the log to locate the problem, but there are two problems:

    1. The tomcat output log under windows is different from that under linux. Linux can connect remotely and use the tail command to easily see the log, and it can be stopped at any time. But the windows log is only input to the console, not output to the log file. This makes the log only visible when the console is open, and ctrl+C cannot stop the interception.
    2. If the remote desktop connection is used, it is impossible for two testers to see the console at the same time, and if VNC, RADMIN and other software are used, it will cause confusion on both sides.
    So I was thinking, it would be nice if I could view the log at any time like linux without manipulating the console.
    Solutions:
    1. Let the tomcat log output to a file. This is clearly achievable.
    2. Find a software that can connect to windows, and use commands to dynamically view log files, such as tail. In fact, most of the commands in linux also have windows, but they are encapsulated by the interface. Now the majority of linux enthusiasts have already developed software that converts windows commands into corresponding linux commands, so it is not a problem.
    Let's start looking for a solution:
    1. Let tomcat log output to a file
Generally, startup.bat is used when starting tomcat, but how many people have really studied what mystery is hidden in this bat file? Let's take a look at this bat file. It uses the sentence call "%EXECUTABLE%" start %CMD_LINE_ARGS% to call catalina.bat to start. The command executed by this sentence is equivalent to inputting catalina.bat start on the console. How, is it very similar to linux, but this start will start catalina.bat in a new window and output the log file to the new window, which is obviously not the effect we want. We changed it to call "%EXECUTABLE%" run %CMD_LINE_ARGS%. In this way, the console will not output log files, and let catalina.bat decide where the log output is.
    Then take a look at catalina.bat. Here I will directly quote the online method: look for four places ending with %ACTION%, and add it after
>> %CATALINA_BASE%\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 the startup will report an error, although it does not matter. That %DATE:~0,10% is used to intercept the system time. Echo %DATE% on my server shows "2013-04-02 Tuesday", intercepting 0-10 digits, which is "2013-04-02", so the name of the log file generated today should be
detailLog.2013-04-02.log
In this way, double-click startup.bat, and you will find that the log file is no longer output after the console is started. Go to view detailLog.2013-04-02.log, and you will find that the logs are all there.
The following work is how to simply display the log file.
    2. Dynamically query windows log files
We all like to use the tail command, so find a tail command in windows.
First download an UnxUtils, put it in a location where you can find it, unzip it, find the ..\UnxUtils\usr\local\wbin directory, see it, all the familiar linux commands are there. Add this path to the server system environment variable PATH, then open cmd, enter tail --help, and display the help information, OK, it can be used. Note that the children's shoes connected to the remote desktop may need to re-save the environment variables for each user, otherwise other users will not recognize this command.
In this case, enter tail logs\detailLog.2013-04-02.log in cmd, just like linux.
    I still find it inconvenient, I have to enter it every time, so why not write a bat file?
    Create a new notepad on the desktop,
    @echo off
    tail -f E:\apache-tomcat-6.0.24-2\logs\detailLog.%DATE:~0,10%.log
    Save as log.bat file. Just double click and you're done!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326253235&siteId=291194637