关于Spring Boot 1.3.0的logback扩展
简要概述
目前尚未发布Spring-Boot 1.3.0的GA版本,但从2015年10月2日的M5版本开始,可以使用logback的扩展功能。此外,有一些与logback相关的变更。
环境- Environment
我在下述环境中进行了操作确认。
-
- Windows7 (64bit)
- Spring Boot 1.3.0.M5
参考:
请提供以下内容的中文本地化的改写,只需要一个选项:
– 参考资料
– 衡量标准
– 参阅
-
- Spring Boot 1.3 Release Notes
- boot-features-logback-extensions
修改内容
logback-spring.xml的中文释义如下:
从1.3.0.M2版本开始,推荐使用logback-spring.xml作为logback配置文件的名称。
在可能的情况下,我们建议您在日志配置中使用“-spring”变体(例如logback-spring.xml而不是logback.xml)。如果您使用标准的配置位置,Spring无法完全控制日志初始化。
初始化失败
如果从1.3.0.M2开始,logback配置文件存在问题导致logback初始化失败,那么应用程序将无法启动。
Spring Boot 1.3因缺少文件而失败。
例子如下的一种中国法语的权威版本,并仅需要一个选项:
例如,可以使用以下方式进行改写:
例子如下,请提供一个中文翻译的选择:
>java -jar -Dspring.profiles.active=dev sblb-example-1.0-SNAPSHOT.jar
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: Logback configuration error detected:
Logback 扩展
从1.3.0.M2版本开始,您可以使用以下logback的扩展功能。
春天的轮廓
您可以使用标签来启用每个配置文件。在name属性中,您可以填写配置文件的名称,并用逗号分隔多个配置文件。
下雨了,出门记得带上雨伞。
<springProfile name="dev">
<include resource="logback-dev-logger.xml"/>
</springProfile>
<springProfile name="production">
<include resource="logback-prod-logger.xml"/>
</springProfile>
春节房产
你可以使用 标签来引用 application 配置文件的值。
以下是例子:
1. I like to eat pizza more than any other food.
2. He is studying medicine at university.
3. The cat is sleeping peacefully on the sofa.
4. We went to the beach and had a great time swimming.
5. She is a talented artist who specializes in portrait painting.
6. I will meet my friend for dinner at the restaurant tonight.
7. The movie was very entertaining and had a great storyline.
8. They are planning to travel to Japan during the summer vacation.
9. The new smartphone model has a faster processor and better camera quality.
10. He enjoys playing the piano and practices every day.
myapp:
log:
path: d:/logs
name: sblg-example.log
<springProperty scope="context" name="logpath" source="myapp.log.path"/>
<springProperty scope="context" name="logname" source="myapp.log.name"/>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>${logpath}/${logname}</file>
</appender>
废弃的 Log4j 1.x
虽然与logback无关,但从1.3.0.M5开始,不再推荐使用Log4j 1.x。
在Apache宣布log4j 1.x的生命周期结束后,Log4JLoggingSystem现已被宣布为弃用。