我试图通过springboot下的配置文件拆分我的logback.xml,这是我的方法:
的logback-prod.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:- ${java.io.tmpdir:-/tmp}}/}spring.log}"/>
<include resource="org/springframework/boot/logging/logback/file- appender.xml" />
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
</configuration>
Run Code Online (Sandbox Code Playgroud)
的logback-dev.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<root level="DEBUG">
<appender-ref ref="CONSOLE" />
</root>
Run Code Online (Sandbox Code Playgroud)
logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="logback-${spring.profiles.active}.xml"/>
<root level="INFO">
<appender-ref ref="FILE" />
<appender-ref ref="CONSOLE" />
</root>
Run Code Online (Sandbox Code Playgroud)
最后使用:
-Dspring.profiles.active=dev
or
-Dspring.profiles.active=prod
Run Code Online (Sandbox Code Playgroud)
我进入了控制台:
13:01:44,673 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@2:16 - no applicable action for [configuration], current ElementPath is [[configuration][configuration]]
13:01:44,674 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@3:81 …Run Code Online (Sandbox Code Playgroud) 当我停止运行我的spring-boot应用程序时,产生了两个日志文件而不是一个(一个是预期的).
我的Logback-test.xml文件中可能导致此错误的是什么?
的logback-的test.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<timestamp key="myTimestamp" datePattern="yyyy-MM-dd'_'HH-mm-ss.SSS"/>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<logger name="org.springframework.web" level="INFO"/>
<!-- Send debug messages to System.out -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- By default, encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} - %msg%n</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>C:\path\to\my\file\myLog-${myTimestamp}.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%d{yyyy-MM-dd_HH:mm:ss.SSS} - %msg%n</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<FileNamePattern>myLog.%i{yyyy-MM-dd_HH:mm:ss.SSS}}.log</FileNamePattern>
<MinIndex>1</MinIndex>
<MaxIndex>10</MaxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>2MB</MaxFileSize>
</triggeringPolicy>
</appender>
<logger name="com.my.package" level="INFO" additivity="false">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" /> …Run Code Online (Sandbox Code Playgroud) 我正在使用 Spring Boot 构建一个简单的 REST 服务,我想知道处理日志记录的最合适的方法。
在我的application.properties文件中,我有以下内容:
logging.level.org.springframework.web: DEBUG
Run Code Online (Sandbox Code Playgroud)
在开发应用程序时,我只是这样运行它:
java -jar myapp.war
Run Code Online (Sandbox Code Playgroud)
因此,我在标准输出中获得了所有不错的日志消息。但是,我打算部署它,我想知道部署应用程序并仍然保留日志的最合适方法是什么。
当然,可以简单地重定向输出
java -jar myapp.war >> somefile
Run Code Online (Sandbox Code Playgroud)
但这不是很优雅,我想部署我的应用程序,以便它可以轻松地用作服务:
ln -s /my/app/xyz.war /etc/init.d/xyz
Run Code Online (Sandbox Code Playgroud)
然后,做
service xyz start|stop|restrart
Run Code Online (Sandbox Code Playgroud)
来管理它。似乎这样做会阻止我重定向 stdout ..
对此有何想法或建议?