springboot logback-spring.xml 为何生成了文件却没有内容

本文探讨了Springboot应用中logback-spring.xml配置导致生成日志文件但无内容的问题。当缺少特定配置时,日志文件会被创建,但无法记录内容。解决方案可能涉及在配置中指定文件名、大小等关键参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

引用:http://120.203.18.89:6969/29/%E5%8E%9F-springboot-logback-spring-xml-%E4%B8%BA%E4%BD%95%E7%94%9F%E6%88%90%E4%BA%86%E6%96%87%E4%BB%B6%E5%8D%B4%E6%B2%A1%E6%9C%89%E5%86%85%E5%AE%B9/

先看我的logback-spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
	<include
		resource="org/springframework/boot/logging/logback/base.xml" />
	<logger name="org.springframework.web" level="INFO" />
	<logger name="org.springboot.sample" level="TRACE" />
	 
	<springProfile name="dev">
		<appender name="FILE"
			class="ch.qos.logback.core.rolling.RollingFileAppender">
			<rollingPolicy
				class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
				<!--日志文件输出的文件名 -->
				<FileNamePattern>./logs/spring-boot-example.%d{yyyy-MM-dd}.log
				</FileNamePattern>
				<!--日志文件保留天数 -->
				<maxHistory>15</maxHistory>
				<totalSizeCap>30GB</totalSizeCap>
			</rollingPolicy>
			<encoder
				class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
				<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}
					- %msg%n</pattern>
			</encoder>
			<!--日志文件最大的大小 -->
			<triggeringPolicy
				class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
				<MaxFileSize>10MB</MaxFileSize>
			</triggeringPolicy>
		</appender>

	</springProfile>
	<!-- 开发、测试环境 -->
	<springProfile name="dev,test">
		<logger name="org.springframework.web" level="INFO" />
		<logger name="org.springboot.sample" level="INFO" />
		<logger name="io.renren" level="DEBUG">
			<appender-ref ref="FILE" />
		</logger>

	</springProfile>

	<!-- 生产环境 -->
	<springProfile name="pro">
		<logger name="org.springframework.web" level="ERROR" />
		<logger name="org.springboot.sample" level="ERROR" />
		<logger name="io.renren" level="ERROR" />
	</springProfile>


</configuration>

 

其中如果没有配置:

 

 

<appender-ref ref="FILE" />

就会出现只创建了文件,没有内容打印进去的现象。

反过来推理,应该是第一个<springProfile name = "dev">定义了保存的文件名及文件大小等一些信息。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xcl119xxcl

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值