• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

variable substitution in log4j properties file

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when I use variable substitution to point to the directory where I want log4j-1.2.8 to put my log file, log4j throws a FileNotFoundException when tomcat is restarted.

in line 7 of the properties file (below) the $CATALINA_HOME system property is referenced using standard log4j sytax. when line 8 replaces line 7, everything works fine.

$CATALINA_HOME is set to:
/home/jholme/ImageAtlasRel/jakarta-tomcat-4.1.18/

what is wrong with this properties file?

1 # AdminOne Log Properties
2 log4j.logger.adminOne=INFO,ao
3 log4j.additivity.adminOne=false
4 # log to a file
5 log4j.appender.ao=org.apache.log4j.DailyRollingFileAppender
6 log4j.appender.ao.DatePattern='.'yyyy-MM-dd
7 log4j.appender.ao.File=${CATALINA_HOME}logs/AdminOneLog.log
8 #log4j.appender.ao.File=/home/jholme/ImageAtlasRel/jakarta-tomcat-4.1.18/logs/AdminOneLog.log
9 # layout
10 log4j.appender.ao.layout=org.apache.log4j.PatternLayout
11 log4j.appender.ao.layout.ConversionPattern=%-5p : %m (%d{yyyy-MM-dd HH:mm:ss})%n

by the way, the log4j exception looks like this (minus the stacktrace):

log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: /logs/AdminOneLog.log (No such file or directory)
log4j:ERROR Either File or DatePattern options are not set for appender [ao].
 
John Holme
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just for the record...

one of my co-workers helped me work this out:

$CATALINA_HOME is an environment variable in tcsh. What the log4j properties file wants is a JVM system property. apples and oranges :-)

but tomcat comes to the rescue! the default catalina.sh file sets a system property when executing the Java code that starts Tomcat:

-Dcatalina.home="$CATALINA_HOME"

so if I use ${catalina.home} instead of ${CATALINA_HOME} in the log4j properties file, it all works as expected.

those crazy shell games...
 
I child proofed my house but they still get in. Distract them with this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!