<dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.2</version> </dependency> import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class LoggerExample { private static final Log LOGGER = LogFactory.getLog(LoggerExample.class); public void exampleMethod() { LOGGER.debug("This is a debug message."); LOGGER.info("This is an info message."); LOGGER.warn("This is a warning message."); LOGGER.error("This is an error message."); LOGGER.fatal("This is a fatal message."); } } <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> log4j.rootLogger=DEBUG, console log4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.console.layout=org.apache.log4j.PatternLayout log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}.%M():%L - %m%n public static void main(String[] args) { LoggerExample example = new LoggerExample(); example.exampleMethod(); } 2022-01-01 12:00:00 DEBUG LoggerExample.exampleMethod():7 - This is a debug message. 2022-01-01 12:00:00 INFO LoggerExample.exampleMethod():8 - This is an info message. 2022-01-01 12:00:00 WARN LoggerExample.exampleMethod():9 - This is a warning message. 2022-01-01 12:00:00 ERROR LoggerExample.exampleMethod():10 - This is an error message. 2022-01-01 12:00:00 FATAL LoggerExample.exampleMethod():11 - This is a fatal message.


上一篇:
下一篇:
切换中文