Win a copy of Terraform in Action this week in the Cloud forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Al Hobbs
  • salvin francis

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

Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 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 file on the JVM command-line on Windows.


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

log4j.rootLogger=INFO, FILE

log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

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

Posts: 26915
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
Saloon Keeper
Posts: 24598
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

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/ Note that this is the literal name it would expect without me putting quotes around the name string.
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic