In this video, we will learn the basics of Java Logging API and its components – Logger, Handlers, and Formatters.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
package tube.coding.examples.javaadv; import java.util.logging.Level; import java.util.logging.Logger; public class Adv001_Logging { //Sample 01: Get the Logger instance Logger logger = Logger.getLogger("Log Tester"); public Adv001_Logging() { super(); logger.setLevel(Level.WARNING); } //Sample 02: Logging with Different Level public void MethodSev() { logger.severe("Severe Error"); } public void MethodWarn() { logger.warning("Warning Message"); } public void MethodInfo() { logger.info("Information Message"); } public static void main(String[] args) { //Sample 03: Test the Logging Adv001_Logging obj = new Adv001_Logging(); obj.MethodSev(); obj.MethodWarn(); obj.MethodInfo(); } } |
Categories: Java-Tube