Avatar of abuyusuf
abuyusuf
 asked on

Using Java Util Logging

I am using Java util logging to log information - I am also using a custom formatter - the custom formatter works fine however the issue that I am facing is that the log file refreshes each time and I loose the old information. The following is the structure of my property file. How can I ensure that the information gets logged to the same file and a new file does not get generated each time.

# The following creates two handlers
handlers=java.util.logging.FileHandler
 
# Set the default logging level for the root logger
.level = INFO
   
# Set the default logging level for new FileHandler instances
java.util.logging.FileHandler.level = INFO
   
# Set the default formatter for new ConsoleHandler instances
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
   
# The custom logging properties file is loaded by specifying a system property on the command line:
# java -Djava.util.logging.config.file=mylogging.properties <class>

Thanks
Java

Avatar of undefined
Last Comment
for_yan

8/22/2022 - Mon
for_yan



Perhaops you want to create appenidng FileHandler like in this example:


http://stackoverflow.com/questions/5341034/java-logger-problem

down vote favorite
	

I would like to record the logs of my Java application. I have created this class:

public class Log {

    final Logger logger = Logger.getLogger("DigiScope.log");

    public static void main(String[] args) {
    }

    public Log(String message) {
        try {
            // Create an appending file handler
            boolean append = true;
            FileHandler handler = new FileHandler("my.log", append);

            // Add to the desired logger
            Logger logger = Logger.getLogger("com.mycompany");
            logger.addHandler(handler);
            logger.info(message);

        } catch (IOException e) {
        }

    }
}

Open in new window

abuyusuf

ASKER
I already did that
for_yan

And it still writes new file every time?
You mean every time you re-start the program?
Do you mean that it writes new file with new name?
What will be the new name?
Or it overwrites into the same file?

Please,provide some details.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
abuyusuf

ASKER
It overwrites the same file - I dont want to loose the logs from a previous run of the program
ASKER CERTIFIED SOLUTION
for_yan

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question