Java by API/java.util.logging/ConsoleHandler
Версия от 17:43, 31 мая 2010; (обсуждение)
new ConsoleHandler()
import java.io.IOException;
import java.util.logging.ConsoleHandler;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Logger;
import java.util.logging.XMLFormatter;
public class MainClass {
public static void main(String args[]) {
Logger logger = Logger.getLogger("my.log");
Handler handler = null;
try {
handler = new FileHandler("messages.log");
} catch (IOException e) {
System.out.println("Could not create file. Using the console handler");
handler = new ConsoleHandler();
}
logger.addHandler(handler);
handler.setFormatter(new XMLFormatter());
logger.info("Our first logging message");
logger.severe("Something terrible happened");
}
}