Syntax Highlighter

개발/ETC2008. 3. 18. 09:47
728x90

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

public class MyLogger {

  public static void main(String[] args) {

    Logger logger = Logger.getLogger("MyLog");
    FileHandler fh;

    try {

      // This block configure the logger with handler and formatter
      String log = "My first log";
      fh = new FileHandler("MyLogFile.log", true);
      logger.addHandler(fh);
      logger.setLevel(Level.ALL);
      SimpleFormatter formatter = new SimpleFormatter();
      fh.setFormatter(formatter);

      // the following statement is used to log any messages
      logger.log(Level.WARNING, log);
      logger.log(Level.FINEST, log);
      logger.log(Level.FINER, log);
      logger.log(Level.FINE, log);
      logger.log(Level.CONFIG, log);
      logger.log(Level.INFO, log);
      logger.log(Level.SEVERE, log);

    } catch (SecurityException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

  }

}



728x90

작성자

Posted by 일퍼센트

관련 글

댓글 영역