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

Saving logfiles to folders created on date

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I used java.util.logging for my java project to create two logfiles (test.log and test.html).
Here's how it looks like.


What i want to do now is save these logfiles to a folder which are created when the program has started en use the date and time as naming.

This is what the result should look like if it's possible.

LOGFILES(folder)=> 14/05/2013(folder) => 09:23(folder) => test.html, test.log(files)
LOGFILES(folder)=> 14/05/2013(folder) => 13:54(folder) => test.html, test.log(files)
LOGFILES(folder)=> 15/05/2013(folder) => 11:15(folder) => test.html, test.log(files)
LOGFILES(folder)=> 15/05/2013(folder) => 18:00(folder) => test.html, test.log(files)

Can anyone help me with this.
I hope my question was clear enough.
 
Bartender
Posts: 10777
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Maikel Geelen wrote:Can anyone help me with this.
I hope my question was clear enough.


Perfectly; however, we don't like to simply hand out code on this site.

What you need to do is to break down the problem, which, as I see it, has at least three parts:
1. How do you get a date String.
2. How do you get a time String.
3. How you you plug that into your FileHandler.

For the first two, I suggest you look at SimpleDateFormat.
For the last, read the API documentation for FileHandler carefully. It actually specifies a pattern, which contains some other stuff that you might find useful.

If you can write:
Handler fh = new FileHandler("someDrive:someDirectory/test.html");
Surely it's pretty straightforward to do what you want.

Winston

PS: Unless you really need it, or you've been told to do it that way, I'd suggest that directories by time is overdoing it a bit. Why not just make it a prefix to your filename?
 
Maikel Geelen
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So far i have created it like this.
I also left away the folder for the time and implemented it in the file itself.



The first filehandler works but the second doesn't because the filehandler can't create the "date" folder.
Here's the error i'm getting.



Is there some sort of argument i'm forgetting or maybe a property of the filehandler? Or is it something with permissions?
 
Winston Gutkowski
Bartender
Posts: 10777
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Maikel Geelen wrote:Is there some sort of argument i'm forgetting or maybe a property of the filehandler? Or is it something with permissions?


To be honest, I don't know; I haven't used loggers much.

One possibility might be to try swapping the two assignments around, since the second is "deeper" than the first; but I honestly don't know if it'll make any difference.

Winston
 
Marshal
Posts: 65464
249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved discussion as too difficult for “beginning”
 
I like tacos! And this tiny ad:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!