I'm currently writing a bash script to copy log files from one host server to another host server. I have an application installed and running on a Websphere application server. The script would copy both the Server logs as well as application log to a remote staging directory. I can retrieve the server log files' path using wsadmin
. I'm facing a challenge to retrieve the application log file path from log4j.properties
under WEB-INF/classes
directory.
Currently, I'm hard coding the log file path in a csv and from the csv, I'm retrieving it and using the command :
find <LOG_FILE_PATH> -type f -name $filename -newermt "$user_date_from" ! -newermt "$user_date_to"
Sample csv file content:
user@server_IP,AppServerName,LogFilePath,IdentifierToDifferentiateWhetherFileisServerLogOrAppLog
I want to do away with this csv file hard coding option because:
- I know that
log4j.properties
already stores the log file paths. - I want to retrieve the log file path from
log4j.properties
instead at runtime, just to make sure that I do not have to update the csv hard coded value in case there is any change inlog4j.properties
.
Sample log4j.properties file content:
logFileLoc=<AbsoluteLogFilePath>
log4j.rootLogger=INFO,RollingAppender,stdout
log4j.appender.RollingAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.RollingAppender.File=${logFileLoc}/<logFileName>.log
log4j.appender.RollingAppender.append=true
log4j.appender.RollingAppender.DatePattern='.'yyyy-MM-dd
log4j.appender.RollingAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.RollingAppender.layout.ConversionPattern=[%p] %d %c %M - %m%n
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{2}:%L - %m%n
So, I wonder if there exists any wsadmin
like admin service available with log4j that can serve my purpose? Any help will be much appreciated.