This week's book giveaways are in the iOS and Features new in Java 8 forums. We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line! See this thread and this one for details.
say I have a bunch of java files in a package a.b.c, I stored the package name a.b.c as a String constant in the class Const in the package a.b.c. Every class in this package holds a member variable like this:
then this logger is used in many places in a java file.
This project has a GUI, I want to keep all the logging infomation in _one_ log file until the main program shuts down. But the situation is...:
when the window gets initialised, happily I have all the initialisation info in the log file and on the console. But after I pressed a button, say, caculate 1, the log file changed. All the previous infomation was gone. Then, if I pressed yet another button, say, caculate 2, the log file changed again. It keeps only the log info of the last action I take. How to fix this problem? I want all the logging info in one file, but not only the very last part...
here is my logging.properties file:
And, I don't know what is wrong, before I added the logging statements, the program was fast, a caculation could finish in 0.X second. But, after the logging statements were added, it becames incredibly slow, the same caculation as before takes half minute. It bugs me very much. Anyway I don't have more than 20 logging statements in one class, and the whole package has only about 10 classes...Is logging that expensive? I don't believe! There must be something wrong in the way I am using the logging API. Could anyone please kindly enlighten me a little bit? Thank you very much in advance!
Regards, Ellen [ March 05, 2005: Message edited by: Ellen Zhao ]
I haven't used Java's built-in logging (only Log4j), but the FileHandler JavaDocs say that limit is the approximate size in bytes for the file. However, given that you're not using file rotation, maybe it's simply deleting the file and creating a new one when it reaches the limit?
That it only shows the last log message makes me believe that the source of your performance drag is that it is deleting and recreating the file with each message logged. I don't see why it would do that with a limit of 50,000 unless you're logging huge strings, but that's the only thing that makes sense.
Since you want to have one log file for the entire application run, I'd remove the limit property entirely. Try that and see what happens.
Joined: Sep 17, 2002
Hi Mr. Harkness,
I tried that and it did solve the problem...the size of the log file after two blocks of caculations was 7.9MB (!!). Well, it's an iterative numerical computing, so, hundreds/thousands of loops.....the performance did improve a little when I removed the file size limitation. But after I changed the logging level from ALL to INFO, the generated log file was only 9.9 kb and the computing took 0.X second again. Thank you very much!
Joined: Aug 07, 2003
Wow, 7.9MB? Yes, that's a lot of logging. Since much of the cost of logging a message is the I/O overhead, short log messages will have the same impact as long ones (unless they're really long).