File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Problem with Copying and Renaming FIle once it reaches its limit  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem with Copying and Renaming FIle once it reaches its limit  " Watch "Problem with Copying and Renaming FIle once it reaches its limit  " New topic
Author

Problem with Copying and Renaming FIle once it reaches its limit

Mike Anna
Ranch Hand

Joined: Jul 08, 2007
Posts: 117
Dear all,

Following is the code I wrote. I have a simple requirement. I need to update a log file (txt file) everyday. For which, I initally take a file.. and append it with some text. once it reaches a certain size. I rename that file and append it with todays date. However, since the file may reach the specified size at any given point. I take the length of the file and append to the file name.. and decrement the length. As of now, It is making only Two files. One the main file.. and second the renamed file.
The problem is for some reason the length gets stuck at 49. Then I realise it is because the first file is being checked every time(I check for the size).
Could some body please tell me how I could correct this code :


TIA
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Any reason why you don't just use log4j which has a rolling file appender which rolls based on file size?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Mike Anna
Ranch Hand

Joined: Jul 08, 2007
Posts: 117
Thanks Paul, for your reply.

Yes there is a reason I cant use log4j for this.
Because AFAIK log4j doesnt give me any other logging level other than the defaults ( debug,info,...,fatal).
Where as this code, I will modify and have a static method being called in my DAOs with params to append to this file.

I specifically need to be able to add the logs for updates or deletes, so I have to write statements in my DAOs.Is there a simple way I can include *this* functionality using Log4j, curently am using it for logging application related stuff. I have done a lot of googling for this.. but they are way too complex for me to follow. I am crushed under deadlines . If you know of a better way or a solution to this... I will be grateful.

Rgds
[ August 07, 2007: Message edited by: Mike Anna ]
Mike Anna
Ranch Hand

Joined: Jul 08, 2007
Posts: 117
err.. is this too complex a code.. ? :roll:
May be it is.. thts why its posted here.
I am still stuck with this one. Would appreciate any help in this aspect.

Rgds
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


Because AFAIK log4j doesnt give me any other logging level other than the defaults ( debug,info,...,fatal).

Why is this an issue? What other level do you need?


Where as this code, I will modify and have a static method being called in my DAOs with params to append to this file.

Again, I'm not sure how this differs from having a log4j file appender. Is there something I'm missing?
Mike Anna
Ranch Hand

Joined: Jul 08, 2007
Posts: 117
All the souls who tried to help....
May be I do not exceptionally understand Log4j... Heres the completely functional code that will take filename and filesize from a properties file.Inline comments. Thanks to whoever tried to help... enjoy

 
 
subject: Problem with Copying and Renaming FIle once it reaches its limit