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
viornano, is available
Configuration Steps
Log in to the Application VM
Access the OvalEdge VM using SSH or direct terminal access:
ssh <user>@<host-ip>
Copy the Existing log4j.properties File
Navigate to the Tomcat application classes directory and copy the default
log4j.propertiesto an external configuration directory:cp /home/ovaledge/apache-tomcat-10.1.40/webapps/ovaledge/WEB-INF/classes/log4j.properties /home/ovaledge/extprop/Sample Reference Screenshot:
Modify the External log4j.properties File
Edit the copied
log4j.propertiesfile to enable external configuration.Open the file:
vi /home/ovaledge/extprop/log4j.propertiesSample Reference Screenshot:
Comment out the internal configuration reference and uncomment the external path if applicable, for example:
#log4j.rootLogger=INFO, CONSOLE log4j.rootLogger=INFO, FILEAdjust other properties as required (log levels, file locations, patterns, etc.).
Edit the setenv.sh File to Point to External Configuration
Navigate to the Tomcat bin directory:
cd /home/ovaledge/apache-tomcat-10.1.40/binOpen or create the
setenv.shfile:vi setenv.shAdd the following line to specify the external configuration path:
export CATALINA_OPTS="$CATALINA_OPTS -Dlog4j.configuration=file:/home/ovaledge/extprop/log4j.properties"Sample Reference Screenshot:
Restart Tomcat
Apply the configuration by restarting the Tomcat server:
/home/ovaledge/apache-tomcat-10.1.40/bin/shutdown.sh /home/ovaledge/apache-tomcat-10.1.40/bin/startup.sh
Validation
To confirm that the external log4j.properties is in effect:
Review the Tomcat logs (
catalina.outor application logs) to ensure expected log behaviorIntroduce 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.
Last updated
Was this helpful?

