3

I am curious about where would be a good location to store log files on windows. Let's say I have a webstart, or an applet application, therefore there is really no place where they are launched from (no installation directory). So given such a condition, where should I store the log file that program created without being intrusive or dumping a lot of garbage where all that data would be seen.

I have never done anything like this before, but I am very curious now, and really would like to hear some ideas or suggestions.

Thanks to anyone for their help in advance.

QUICK Edit: Let's say I can use absolutely any logging framework or system available (for java), and yes let's say that user has given access to store things within his account (but not general user or anywhere else system related).

Quillion
  • 6,346
  • 11
  • 60
  • 97
  • 2
    What is the logging framework you are using. – Ashish May 23 '13 at 17:55
  • 1
    Do applets and applications from java-web-start even have access to the user's file system without enhanced security permissions i.e. signing your code and asking the user to elevate the access rights of the application in question? – thatidiotguy May 23 '13 at 17:55
  • Interesting question, but ultimately pretty subjective. Probably better for a different forum. – asteri May 23 '13 at 17:59
  • 1
    Where would you recommend I ask this? – Quillion May 23 '13 at 18:17

1 Answers1

4

If you do not have any security constraint and your webstart or applet application can access file system then you can use $(user.home) system property.

It will allow the application to store the log file in the user home and would be operating system independent.

For example I am using Log4j and this is the configuration of my log4j.property file

log4j.appender.F.File=${user.home}/app.logs

If you are using default java logging then you can still fetch this system property and assign it is a log file location.

You can also append any location after $(user.home) if you wants to store the logs in sub directory.

For Example

log4j.appender.F.File=${user.home}/logs/application.log

Amendment:

if you do not want to store anything in home directory, you could get the root directory by navigating upward using getParent until null is returned and once you have root directory you can go to any location in the filesystem

Ashish
  • 14,295
  • 21
  • 82
  • 127
  • I think this is a good idea, but I think it'd be better to use a subdirectory under `$(user.home)`. That way it'll be easier to find and other programs are less likely to clobber it. – Daniel Kaplan May 23 '13 at 17:59
  • @tieTYT thanks, I am absolutely agree with you user can append any location of his choice after that – Ashish May 23 '13 at 18:00
  • Is there a way to also make a subdirectory be a hidden folder? That way it won't be jumping at the user whenever he wants to look in his home for other folders. – Quillion May 23 '13 at 18:04
  • If you wants to hide the folder you can check the solution at [this SO question](http://stackoverflow.com/questions/1999437/how-to-make-a-folder-hidden-using-java) – Ashish May 23 '13 at 18:07
  • 1
    @Quillion Please accept the answer if that satisfy your needs. – Ashish May 23 '13 at 18:09
  • Thanks ashish, this is excellent, I am however open to more ideas, this is purely because I am curious of some very clever ways someone might do it – Quillion May 23 '13 at 18:14