After you install tomcat in macOS, you can start it and stop it with a command. Article How To Install Tomcat In MacOS has told you how to do that.
But after you start it, you can not find the log data in the terminal like windows. This may make you crazy because you can not get debug or error information when the tomcat server can not be accessed. Do not worry, this article will tell you how to show the tomcat live logs in the terminal.
1. Add Tomcat Executable In Path Environment Variable.
- The How To Install Tomcat In MacOS is not perfect because you must go to Tomcat_Home/bin folder to run the startup.sh/shutdown.sh to start/stop the tomcat server for each time. You have to remember the Tomcat_Home directory, this is not user-friendly.
- To resolve the above issue, you can add the Tomcat_Home/bin folder into the OS PATH environment variable value, then you can type startup.sh/shutdown.sh at any directory level to start/stop it. Below are the steps.
- CD into user home directory.
192:~ $ cd ~
- Edit user bash profile file.
192:~ $ vim .bash_profile
- Add Tomcat_Home/bin folder in the PATH variable value. Press i in vim to insert text, then copy and paste Tomcat_Home/bin folder to PATH value.
- Press shift + : then wq! to save the changes.
sourcecommand in the terminal to make the change take effect.
192:~$ source .bash_profile
- Now you can start/stop the tomcat server at any directory level in the terminal.
2. Live Show Tomcat Server Log In Terminal.
- After section one, you can start the tomcat server from anywhere, but after the start, you are confused that it does not output the tomcat logs in the terminal. This makes you seriously when you want to see the log to fix bugs or resolve errors in live time.
- Do not be crazy, let us follow the below steps to show the tomcat log in live time.
- If you do not know where the tomcat is installed, you can run the below command to get it. The tomcat startup.sh will call the catalina.sh to start it.
192:~ $ ps -ef|grep catalina
- Tomcat logs are saved in the Tomcat_Home/logs/catalina.out file. So to live show tomcat logs, you can use tail -f command in the terminal, the tail -f command will display the latest logs in the catalina.out file in terminal.
192:~ $ tail -f /Users/zhaosong/Documents/WorkSpace/tool/apache-tomcat-9.0.8/logs/catalina.out