FileHandler: close() : FileHandler « java.util.logging « Java by API






FileHandler: close()

  


import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.logging.XMLFormatter;

public class Main {
  public static void main(String args[]) throws Exception {
      LogManager lm = LogManager.getLogManager();
      Logger logger;
      FileHandler fh = new FileHandler("log_test.txt");

      logger = Logger.getLogger("LoggingExample1");

      lm.addLogger(logger);
      logger.setLevel(Level.INFO);
      fh.setFormatter(new XMLFormatter());

      logger.addHandler(fh);
       //logger.setUseParentHandlers(false);
      logger.log(Level.INFO, "test 1");
      logger.log(Level.INFO, "test 2");
      logger.log(Level.INFO, "test 3");
      fh.close();
  }
}

   
    
  








Related examples in the same category

1.new FileHandler(String pattern)
2.FileHandler: publish(LogRecord record)