Link to home
Create AccountLog in
Avatar of 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
# 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 <class>

Avatar of for_yan
Flag of United States of America image

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

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");

        } catch (IOException e) {


Open in new window

Avatar of abuyusuf


I already did that
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.
It overwrites the same file - I dont want to loose the logs from a previous run of the program
Avatar of for_yan
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account