I have a number of Windows servers running various versions of Tomcat 8, And I need to be able to acquire the Tomcat log path in a PowerShell script in order to perform administrative functions with this script.
Tomcat allegedly provides a logging API containing this information, but I haven't had any success accessing it with PowerShell (and suspect this is far from the easiest way to get what I want in any event). However, I've noticed that, at least for my Tomcat servers, the log path is a subfolder of the application's install path, such as:
C:\Program Files\Apache Software Foundation\Tomcat 8.0\logs
So, how can I programmatically get this log path from my PowerShell script?
Best Answer
While unsuccessfully searching for a config file or registry setting that might contain the log directory path, I stumbled upon a registry key that contains the installation path of the Tomcat app itself, and combined with the knowledge that the log folder I'm after is in a subfolder of that, named
logs
, I have enough information for my script to create the logging path.This registry key is going to be in a predictable location in the registry, and the "InstallPath" name/property is unique within that location, so I can simply do a recursive search and match "InstallPath" to extract the installation folder for Tomcat, and append
\logs
to get my logging folder.After adding a basic error handling check, that looks like: