logback-spring.xml中<property name="log.path" value="./mrm_logs" />的value来自yml
时间: 2023-12-22 17:03:30 浏览: 92
你好!对于这个问题,您可以在yml配置文件中设置一个属性,然后将该属性的值传递给logback-spring.xml中的<property>元素的value属性。具体步骤如下:
1. 在您的application.yml或application.properties文件中添加一个属性,例如:
```yaml
myapp:
log:
path: ./mrm_logs
```
2. 在logback-spring.xml中,使用`${}`语法引用该属性的值,如下所示:
```xml
<configuration>
<property name="log.path" value="${myapp.log.path}" />
...
</configuration>
```
这样,logback-spring.xml中的log.path属性的值将会从yml配置文件中获取,并且可以动态地根据需要进行更改。
相关问题
logback-spring.xml 中cron具体配置给出完整logback-spring.xml 代码
<?xml version="1.0" encoding="UTF-8"?>
<configuration> <include resource="org/springframework/scheduling/quartz/quartz-context.xml" /> <springProfile name="quartz">
<bean id="logbackJob" class="ch.qos.logback.core.db.JobWithHistory">
<property name="dynamicSql" value="INSERT INTO LoggingEvent (timestmp, formatted_message, logger_name, level_string, thread_name, reference_flag, caller_filename, caller_class, caller_method, caller_line, event_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" />
</bean> <bean id="logbackTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="logbackJob" />
<property name="cronExpression" value="0 0 0 * * ?" />
</bean>
</springProfile></configuration>
logback-spring.xml 配置cron定时器给出完整的logback-spring.xml配置
<configuration>
<springProfile name="production">
<timestamp key="byDay" datePattern="yyyy-MM-dd'T'HH:mm:ss.SSSZ" />
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>/logs/appName-%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>
</springProfile> <springProfile name="cron">
<timestamp key="byCron" datePattern="yyyy-MM-dd'T'HH:mm:ss.SSSZ" />
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>/logs/appName-cron-%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>
<cronTriggeringPolicy class="ch.qos.logback.core.rolling.CronTriggeringPolicy">
<cronExpression>0 0 0 * * ?</cronExpression>
</cronTriggeringPolicy>
</springProfile>
</configuration>
阅读全文