0

I have a requirement wherein I need to put log4j.properties file inside a folder named 'resources' under src directory.

log4j.properties

log = D:\\XYZ
log4j.rootLogger=INFO, FILE

log4j.appender.FILE=org.apache.log4j.FileAppender
resources.log4j.appender.FILE.File=${log}/logger.txt


log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

but my when I navigate through my application nothing gets logged into logger.txt file..I have explicitly not given any configuration for log4j.properties file...

Please point my mistake and suggest solution..I am new to this concept..

Thanks

xyz
  • 139
  • 2
  • 5
  • 15
  • 2
    Log4j cannot find the properties file unless its in the right place, i.e. at the root of the classpath. You can fix this in one of two ways, 1) [configure log4j programatically](http://logging.apache.org/log4j/1.2/manual.html) or, 2) [change the location of the config file](http://stackoverflow.com/questions/7390521/change-location-of-log4j-properties). – Boris the Spider Oct 29 '13 at 09:29

1 Answers1

1

Notice that log4j is using a system property in the configuration, ${log} this needs to be defined when the VM is started. Essentially this is a variable piece of the configuration that is defined by a configuration parameter passed to the application.

java -Dlog=C:\SomeDirectory\ theApp

If your using Eclipse system properties can be set via the Run Configuration for your application.

Kevin Bowersox
  • 93,289
  • 19
  • 159
  • 189