# Externalize log4j.properties

This article outlines the steps to externalize the `log4j.properties` file used by the OvalEdge application, deployed on Apache Tomcat. Externalizing the logging configuration file enables system administrators and DevOps engineers to modify logging behavior (e.g., log levels, file paths, appenders) without requiring repackaging or redeployment of the application.

Apache Log4j is a widely used logging framework in Java applications, and `log4j.properties` serves as its configuration file. Externalizing this file allows for improved maintainability, environment-specific logging behavior, and simplified troubleshooting.

## Prerequisites

Ensure the following conditions are met before proceeding:

* **Access Permissions:** SSH access to the OvalEdge application virtual machine (VM) with sufficient privileges to modify files and restart services
* **Tomcat Installed:** Apache Tomcat v10.1.40 is installed and running the OvalEdge application
* **Java Runtime:** Java is installed and configured correctly on the host system
* **Editor Availability:** A terminal text editor, such as `vi` or `nano`, is available

### Configuration Steps

1. Log in to the Application VM
   * Access the OvalEdge VM using SSH or direct terminal access:

     ```bash
     ssh <user>@<host-ip>
     ```

     <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p>Replace <code>&#x3C;user></code> and <code>&#x3C;host-ip></code> with the appropriate login credentials and IP address.</p></div>

2. Copy the Existing log4j.properties File
   * Navigate to the Tomcat application classes directory and copy the default `log4j.properties` to an external configuration directory:

     ```bash
     cp /home/ovaledge/apache-tomcat-10.1.40/webapps/ovaledge/WEB-INF/classes/log4j.properties /home/ovaledge/extprop/
     ```

     \
     **Sample Reference Screenshot:**

     <figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXezoA5ZQLhztdariWa-ijsV95UeGSKsloecbBVFh6xCxFsnOobynPOd6h_8fmauK-sTOAmrANUUdkW4KeXY0GeJOdPO9d-2UyEf2iCW8yDm3CVHrDnlu_i96dHyoWZ09BEVMYOO?key=_J_fwGHQdMp5Vv86AXngcA" alt=""><figcaption></figcaption></figure>

     <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p>Ensure the directory <code>/home/ovaledge/extprop/</code> exists. Create it using:</p><pre class="language-bash"><code class="lang-bash">mkdir -p /home/ovaledge/extprop/
     </code></pre></div>

3. Modify the External log4j.properties File
   * Edit the copied `log4j.properties` file to enable external configuration.
   * Open the file:

     ```bash
     vi /home/ovaledge/extprop/log4j.properties
     ```

     \
     **Sample Reference Screenshot:**

     <figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXcz9WHN8OYDwjTAxSNikXiIJhnwyaBA1ndYkTxxFaClJlw7QgW_8-P5dUOq9RfANxfpUal3dw722xXaErMOLpvcac3VqRRlyfH5-OrDa4AlgIb1QBus3b0pXneeYcJH0Rg0H7aZ?key=_J_fwGHQdMp5Vv86AXngcA" alt=""><figcaption></figcaption></figure>
   * Comment out the internal configuration reference and uncomment the external path if applicable, for example:

     ```properties
     #log4j.rootLogger=INFO, CONSOLE
     log4j.rootLogger=INFO, FILE
     ```
   * Adjust other properties as required (log levels, file locations, patterns, etc.).<br>

4. Edit the setenv.sh File to Point to External Configuration
   * Navigate to the Tomcat bin directory:

     ```bash
     cd /home/ovaledge/apache-tomcat-10.1.40/bin
     ```
   * Open or create the `setenv.sh` file:

     ```bash
     vi setenv.sh
     ```
   * Add the following line to specify the external configuration path:

     ```bash
     export CATALINA_OPTS="$CATALINA_OPTS -Dlog4j.configuration=file:/home/ovaledge/extprop/log4j.properties"
     ```

     \
     **Sample Reference Screenshot:**

     <figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXf_J0xHvXbyzNaucWzVstZeLIgTB0qJUD-E-Ak4Udc_Bw8er3FejEEjf0AbcYShE1um6A1Ul2b27NJxHHK8HwZ2Zhop_D_UYb2gx1JGF4G7bNHIqg9j9WACRVgor02Y7d8ymc0lVg?key=_J_fwGHQdMp5Vv86AXngcA" alt=""><figcaption></figcaption></figure>

     <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p>Ensure the path is absolute and uses the <code>file:</code> protocol prefix.</p></div>

     &#x20;

5. Restart Tomcat
   * Apply the configuration by restarting the Tomcat server:

     ```bash
     /home/ovaledge/apache-tomcat-10.1.40/bin/shutdown.sh
     /home/ovaledge/apache-tomcat-10.1.40/bin/startup.sh
     ```

     <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p>Wait a few moments and verify that Tomcat has started successfully.</p></div>

### Validation

To confirm that the external `log4j.properties` is in effect:

* Review the Tomcat logs (`catalina.out` or application logs) to ensure expected log behavior
* Introduce a test log message (e.g., set to **DEBUG**) and verify output in the configured log file
* Confirm that no logging configuration errors appear during Tomcat startup

***

Copyright © 2025, OvalEdge LLC, Peachtree Corners, GA, USA.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ovaledge.com/release8.1/deployment-and-maintenance/configuration/externalize-log4j.properties.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
