How To Show Live Tomcat Log In MacOS

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.

  1. 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.
  2. 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.
  3. CD into user home directory.
    192:~ $ cd ~
  4. Edit user bash profile file.
    192:~ $ vim .bash_profile
  5. 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.
    PATH="/Users/zhaosong/Documents/WorkSpace/tool/apache-tomcat-9.0.8/bin:/Users.......
  6. Press shift + : then wq! to save the changes.
  7. Run source command in the terminal to make the change take effect.
    192:~$ source .bash_profile
  8. Now you can start/stop the tomcat server at any directory level in the terminal.

2. Live Show Tomcat Server Log In Terminal.

  1. 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.
  2. Do not be crazy, let us follow the below steps to show the tomcat log in live time.
  3. 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
  4. 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

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.