spring boot logback

项目中遇到了日志处理,在本地可以运行,在服务器上只能输出一部分日志。想着回来看一下,写了个简单的例子。

maven的pom.xml加入:

	
			ch.qos.logback
			logback-classic
			1.0.11
		


类里加入:

	private Logger logger =  LoggerFactory.getLogger(this.getClass());
application.properties里加入:

logging.file=./springboot.log
logging.level.org.springframework.web=INFO
logging.level.com.chao=INFO

想着应该可以了,结果报:

Failed to instantiate [ch.qos.logback.classic.LoggerContext]
Reported exception:
java.lang.AbstractMethodError: ch.qos.logback.classic.pattern.EnsureExceptionHandling.process(Lch/qos/logback/core/Context;Lch/qos/logback/core/pattern/Converter;)V
	at ch.qos.logback.core.pattern.PatternLayoutBase.start(PatternLayoutBase.java:89)
	at ch.qos.logback.classic.encoder.PatternLayoutEncoder.start(PatternLayoutEncoder.java:28)
	at ch.qos.logback.classic.BasicConfigurator.configure(BasicConfigurator.java:50)
	at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)
	at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85)
	at org.slf4j.impl.StaticLoggerBinder.(StaticLoggerBinder.java:55)
	at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
	at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
	at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
	at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155)
	at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
	at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:273)
	at org.springframework.boot.SpringApplication.(SpringApplication.java:179)
	at com.chao.controller.UserController.main(UserController.java:59)

这么简单都会错,怀疑自己智商了。

没看出原因来,去https://mvnrepository.com/看了下,换了个version,1.2.2。好了,这也太神奇了。瞎猫碰到死耗子。

日志也打印出来了。

 
  


你可能感兴趣的:(java,spring,boot,logback.xml)