logger applying for sample java class without adding any jars

Introduction:
Developing any application or even a single class also applying logger is more important to understand or debugging the code. why we add loggers even we can use the sout statements right but there is some disadvantage that is while running the code system.out.println  statements are printed after closing the terminal they have not appeared. in these cases, we can not debug the code also. To rectify this type of problems we can use the loggers. If we use loggers logger file will take care of all these things even we can use sout statements.
Logger

Here is my sample java class:
package demo;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

/**
 *
 * @author Ram Janardhan Randhi
 */
public class Demo {

    private static final Logger LOGGER = Logger.getLogger(Demo.class.getName());

    public static void main(String[] args) throws IOException {
        FileHandler fh = new FileHandler("D://FileUpload.log", true);
        LOGGER.setUseParentHandlers(false);
        LOGGER.addHandler(fh);
        SimpleFormatter formatter = new SimpleFormatter();
        fh.setFormatter(formatter);
        for (int i = 0; i <= 10; i++) {
            System.out.println(i);
            LOGGER.log(Level.INFO, String.valueOf(i));
        }
    }
}
Explanation:
  • Here my java class prints the 1 to 10 numbers.
  • Here I am creating the final variable for getting the class name.
  • Then use the FileHandler instance to create the log file.
  • Then I use these two methods for removes the prevent the logger sends log messages to its parent logger.
  • LOGGER.setUseParentHandlers(false);
  • LOGGER.addHandler(fh);
  • LOGGER.log method for print the logs in a file.
Output:
OutputFile