views:

423

answers:

3

I use java.util.logging.Logger to log in my app :

    FileHandler fh=new FileHandler(this.todayFileName, 0, 1, true);

    fh.setFormatter(new SimpleFormatter());

    Logger.getLogger(rootLogger.getName()).setLevel(Level.ALL);

    Logger.getLogger(rootLogger.getName()).addHandler(fh);

but this does work well except that log rotation is enabled.

and i get files :

run.log run.log.1 run.log.2

what I want is to get only one log file, with no rotation enabled.

how do I do that ?

A: 

If you must use this, then try Integer.MAX_INT instead of 0. The 0 might actually be treated as 0 bytes, and thus cause a rotation every time you initialise it.

BTW if you want 'only one file, no rotation' then use the 1-arg constructor that just takes the file name, and it will do the right thing.

AlBlue
this did not work ! any other suggestion ?
Attilah
From the FileHandler javadoc: "limit specifies an approximate maximum amount to write (in bytes) to any one file. If this is zero, then there is no limit." So setting to 0 should disable the limit, not cause infinite rotation.
joe p
+1  A: 

If you run the same application more than once at the same time, java.util.logging will create many log file like run.log run.log.1 run.log.2

And are you sure that your application close correctly, because I already got this problem. Since my application didn't close correctly, when I started my application, that created a myApplication.log.1

Nettogrof
A: 

Hi,

You must use the FileHandle constructor tht uses a file name and a boolean or the one that uses the file name only, in this way you are going to get a single log file with no rotation.

Regards, Luis.

Hikaru77