<dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.2</version> </dependency> groovy implementation 'commons-logging:commons-logging:1.2' import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class MyClass { private static final Log log = LogFactory.getLog(MyClass.class); public void myMethod() { log.debug("Debug message"); log.info("Info message"); log.warn("Warning message"); log.error("Error message"); } } properties # Log levels log4j.rootLogger=INFO, console log4j.logger.org.apache.commons.logging=INFO # Console appender 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}:%L - %m%n import org.apache.commons.logging.LogFactory; import org.apache.log4j.PropertyConfigurator; public class MyApp { public static void main(String[] args) { PropertyConfigurator.configure("log4j.properties"); org.apache.commons.logging.Log log = LogFactory.getLog(MyApp.class); log.info("Info message"); } }


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