1

I used java.util.logging to create two logfiles. Here's how it looks like.

Handler fh = new FileHandler("%h/AntonGUI_Tester/Logfiles/"+logTime+".html");
fh.setFormatter(new HTMLTableFormatter());        
logger.addHandler(fh);
logger.setLevel(Level.START);    

Handler fh2 = new FileHandler("%h/AntonGUI_Tester/Logfiles/"+logDate+"/"+logTime+".log");
fh2.setFormatter(new TextFormatter());
logger2.addHandler(fh2);
logger2.setLevel(Level.ALL);

I want to create the file based on time and i want it to be saved in a folder based on the date. The first FileHandler works but the second doesn't because for some reason it can't create the directory.

Here's my error.

Exception in thread "main" java.io.IOException: Couldn't get lock for %h/AntonGUI_Tester/Logfiles/15-05-2013/13-19-25.log
    at java.util.logging.FileHandler.openFiles(FileHandler.java:372)
    at java.util.logging.FileHandler.<init>(FileHandler.java:237)
    at main.STSMain.main(STSMain.java:77)

Is there a property i have to change or does it have something to do with permissions?

If you need more code or if my question wasn't clear enough let me know.

Tiago Sippert
  • 1,324
  • 7
  • 24
  • 33

1 Answers1

0

It's because FileHandler class does not create subdirectories dynamicly, you have to create the date directory before instanciating your FileHandler.

Maybe you forgot to use the "logDate" in you first example.

Regards,

gma
  • 2,563
  • 15
  • 14