• 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
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

how to set log4j properties file on JVM command-line using relative path on Windows and log file

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
 Using Eclipse on Windows.  Using log4j - yes, I know it is deprecated :-)  This is a desktop app, not a web app btw.

 I need to know how to set the relative path location of the log4.properties file on the JVM command-line on Windows.

-Dlog4j.configuration=file:"./resources/log4j.properties"

and also I need to set the relative path location of the log file in the log4j.properties file on Windows.

log4j.rootLogger=INFO, FILE

log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.File=./appl.log
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.appender.FILE.MaxFileSize=5MB
log4j.appender.FILE.MaxBackupIndex=5
log4j.appender.FILE.append=true

I have tried numerous variations and cannot get a log file to generate.

 
Marshal
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Relative path" means relative to the current working directory. So your question seems to boil down to how do you set the current working directory -- or maybe you just need to know what it is so that you can find the place the logs are written to?

Frankly I'd suggest not relying on the current working directory, unless you have a foolproof method of setting it to a place you want it to be. Use the full path instead.
 
Bartender
Posts: 20847
125
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Relative directory paths are minefields, especially if you have a complex system where possibly more than one thread might set the current directory. And note also, that Windows doesn't have just one current directory - there's one for each drive ID. It's only the "current" current directory - the one on the currently-logged drive that matches the Java concept of such.

One of the useful things about the Unix-like OS's is that there's a specific directory for log files. Windows never defined such, since they expected you'd use the Event Manager.

Anyway, I think there's a problem with the following:


It would probably work better as:
[/code]
-Dlog4j.configuration="file:./resources/log4j.properties"
[/code]

Or even


I'm afraid that the command-line parser wouldn't properly interpret where you put your opening quote and it ended up looking for a file named "./resources/log4j.properties. Note that this is the literal name it would expect without me putting quotes around the name string.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!