After you install tomcat in MacOS, you can start it and stop it with 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 live show the tomcat 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 startup.sh/shutdown.sh to start/stop the tomcat server for each time. You have to remember Tomcat_Home directory, this is not user friendly.
To resolve above issue, you can add 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 steps.
- CD to 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 terminal to make the change take effect.
192:~$ source .bash_profile
- Now you can start/stop tomcat server at any directory level in terminal.
2. Live Show Tomcat Server Log In Terminal.
After section one, you can start tomcat at anywhere, but after start you are confused that it do not output the tomcat logs in the terminal. This make you seriously when you want to see the log for fix bugs or resolve error in live time.
Do not crazy, let us follow bellow steps to show the tomcat log in live time.
- If you do not know where the tomcat installed, you can run below command to get it. The tomcat startup.sh will execute catalina.sh to start it.
192:~ $ ps -ef|grep catalina
- Tomcat logs are saved in Tomcat_Home/logs/catalina.out file. So to live show tomcat logs, you can use tail -f command in terminal, 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