Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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();
    }
}