Java standard logger

Way of thinking

  1. Create a logger.
  2. Create a handler to receive the log.
  3. Set the handler on the logger.
  4. Set the log level.
  5. Output the log.

Sample code

1, Creating a logger

private static final Logger logger = Logger.getLogger(MyClass.class.getName());

2, Create handler

//Handler to receive the log as a file
FileHandler fileHandler = new FileHandler(String filepath, true);
fileHandler.setFormatter(new SimpleFormatter());

//Standard output handler
ConsoleHandler consoleHandler = new ConsoleHandler();
consoleHandler.setLevel(Level.ALL);

3, set a handler for the logger

logger.addHandler(fileHandler);
logger.addHandler(consoleHandler);
logger.setLevel(Level.ALL);

4, set the log level

logger.setLevel(Level.ALL);

5, output log

logger.finest("FNST");
logger.finer("FNR");
logger.fine("FN");
logger.config("CFG");
logger.info("INF");
logger.warning("WNG");
logger.severe("SVR");

Recommended Posts

Java standard logger
java standard functional interface
Java memo (standard class) substring
Java memo (standard class) length
Read standard input in Java
Java
Java standard log output sample
[Java] List OS-dependent standard libraries
Java
Use Microsoft Graph with standard Java
Studying Java ―― 3
[Java] array
Java protected
[Java] Annotation
Story of paiza.jp [Java standard input solution]
[Java] Module
Java array
Studying Java ―― 9
Java scratch scratch
Java tips, tips
Java methods
Java method
java (constructor)
Java array
[Java] ArrayDeque
java (override)
java (method)
Java Day 2018
Java string
java (array)
Java static
Java serialization
java beginner 4
JAVA paid
Studying Java ―― 4
java shellsort
[Java] compareTo
java reflexes
java (interface)
Java memorandum
☾ Java / Collection
Java array
Studying Java ―― 1
[Java] Array
[Java] Polymorphism
Java review
java framework
Java features
[Java] Inheritance
FastScanner Java
Java features
[Java] Use cryptography in the standard library
java beginner 3
Java memo
java (encapsulation)
Java inheritance
[Java] Overload
Java basics
Decompile Java
[Java] Annotation
java notes