今天项目在 Win10 系统上面启动程序,抛出了如下错误信息:
10:34:45,225 |-WARN in ch.qos.logback.core.ConsoleAppender[stdout] - Failed to create WindowsAnsiOutputStream. Falling back on the default stream. ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type org.fusesource.jansi.WindowsAnsiOutputStream at ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type org.fusesource.jansi.WindowsAnsiOutputStream at at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:72) at at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:40) at at ch.qos.logback.core.ConsoleAppender.getTargetStreamForWindows(ConsoleAppender.java:94) at at ch.qos.logback.core.ConsoleAppender.start(ConsoleAppender.java:85) at at ch.qos.logback.core.joran.action.AppenderAction.end(AppenderAction.java:96) at at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:318) at at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:197) at at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:183) at at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:62) at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:147) at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:133) at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:96) at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:55) at at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75) at at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:148) at at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84) at at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:54) at at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128) at at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:107) at at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:295) at at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:269) at at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:156) at at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132) at at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685) at at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:269) at at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) at at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939) at at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434) at at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) at at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) at at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633) at at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1113) at at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1671) at at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) at at java.util.concurrent.FutureTask.run(FutureTask.java) at at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.ClassNotFoundException: org.fusesource.jansi.WindowsAnsiOutputStream at at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714) at at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559) at at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:59) at ... 39 common frames omitted
(1)什么是 jansi ?
Jansi 是一个 Java 类库,它能够让你在控制台输出色彩缤纷的文字。在 Logback 中,使用了 jansi 来实现控制台多颜色输出日志。
(2)配置 logback,关闭 jansi
<!-- stdout appender定义 --> <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender"> <withJansi>true</withJansi> <layout class="ch.qos.logback.classic.PatternLayout"> <pattern>%date [%thread] %-5level %logger{80} - %msg %file%n</pattern> </layout> </appender>
将 withJansi 修改为 false 即可。修改后如下:
<!-- stdout appender定义 --> <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender"> <withJansi>false</withJansi> <layout class="ch.qos.logback.classic.PatternLayout"> <pattern>%date [%thread] %-5level %logger{80} - %msg %file%n</pattern> </layout> </appender>
到这里,这个问题解决了。
这问题总的来说就是自己不知道什么是 jansi,根据 org.fusesource.jansi.WindowsAnsiOutputStream 类的全名可以知道 jansi 工具(官网:https://fusesource.github.io/jansi/ )。知道了 jansi 是什么后,继续查看日志,这个问题是由 logback 引起的。那么就去找找 logback 和 jansi 的关系,看看是否能够通过配置文件进行禁用。
赞,终于在垃圾堆里找到你这正确的解决方法了
控制台不能显示彩色文字了,这不是解决办法
谢谢支持