我有Spring Boot 2.0.0.M3
版本和logback 1.2.3
以及下一个配置文件:
<configuration debug="true">
<springProfile name="local">
<springProperty name="springAppName" source="spring.application.name"/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%green(%d{yyyy-MM-dd HH:mm:ss}) [${springAppName},%X{X-B3-TraceId:-},%X{X-B3-SpanId:-},%X{X-Span-Export:-}] %highlight(%-5level) %cyan(%logger{15}) %m%n</pattern>
<charset>utf8</charset>
</encoder>
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator>
<expression>logger.contains("test")</expression>
</evaluator>
<onMatch>DENY</onMatch>
</filter>
</appender>
<root level="info">
<appender-ref ref="CONSOLE"/>
</root>
</springProfile>
</configuration>
但每当我启动我的应用程序时,它都会失败。我有下一个日志:
11:35:16,891 |-WARN in Logger[org.springframework.core.env.PropertySourcesPropertyResolver] - No appenders present in context [default] for logger [org.springframework.core.env.PropertySourcesPropertyResolver].
11:35:16,891 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
11:35:16,891 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [CONSOLE]
11:35:16,896 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
11:35:16,930 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.boolex.JaninoEventEvaluator] for [evaluator] property
Process finished with exit code 1
我觉得EvaluatorFilter有什么问题我应该选择具体的并为它添加一些额外的依赖项吗?
答案 0 :(得分:1)
这是你正在使用的表达方式吗?试试这个...
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator> <!-- defaults to type ch.qos.logback.classic.boolex.JaninoEventEvaluator -->
<expression>return formattedMessage.contains("test");</expression>
</evaluator>
<OnMismatch>NEUTRAL</OnMismatch>
<OnMatch>DENY</OnMatch>
</filter>
此评估程序过滤器将删除其消息包含字符串&#34; test&#34;的所有日志记录事件。
答案 1 :(得分:0)
是否需要使用logback的依赖项?
见Logback dependencies page。特别是要让Bifunctor[Either].bimap(Right(1): Either[String, Int])(_.toUpperCase, _ + 1).println
工作,JaninoEventEvaluator
及其依赖关系Janino
是必需的。
我看到同样的问题,当这两个不在类路径中时,应用程序只是以退出代码1静默退出。