import java.util.logging.Level;
import java.util.logging.Logger;
public class ExampleClass {
private static final Logger LOGGER = Logger.getLogger(ExampleClass.class.getName());
public static void main(String[] args) {
LOGGER.log(Level.INFO, "This is an info message.");
LOGGER.log(Level.WARNING, "This is a warning message.");
LOGGER.log(Level.SEVERE, "This is an error message.");
}
}
properties
handlers=java.util.logging.ConsoleHandler
.level=INFO
java.util.logging.ConsoleHandler.level=INFO
import java.util.logging.Level;
import java.util.logging.Logger;
public class ExampleClass {
private static final Logger LOGGER = Logger.getLogger(ExampleClass.class.getName());
public static void main(String[] args) {
LOGGER.log(Level.INFO, "This is an info message.");
LOGGER.setLevel(Level.FINE);
LOGGER.log(Level.FINE, "This is a debug message.");
}
}
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class ExampleClass {
private static final Logger LOGGER = LogManager.getLogger(ExampleClass.class);
public static void main(String[] args) {
LOGGER.info("This is an info message.");
LOGGER.warn("This is a warning message.");
LOGGER.error("This is an error message.");
}
}
yaml
configuration:
appenders:
- Console:
name: ConsoleAppender
target: SYSTEM_OUT
PatternLayout:
pattern: "%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"
loggers:
- logger:
- name: com.example.ExampleClass
level: info
additivity: false
appender-ref:
- ref: ConsoleAppender