日志配置文件中 file 属性和 fileNamePattern 属性的区别

135 阅读1分钟

在使用 springboot 项目整合日志的时候,配置xml文件中可以设置 file 和 fileNamePattern 这两个标签。

image.png

其中这两个属性都是设置保存地址,如果 file 属性设置了地址为 c:\log\log.log,fileNamePattern 属性设置了 c:\log/log-%d{yyyy-MM-dd}.%i.log,maxHistory 属性设置为 1 天。

1、2024年4月19号这一天中程序每次产生的日志信息都会保存在 c:\log\log.log 中;

2、2024年4月20号就会将 c:\log\log.log 文件改名为 c:\log/log-20240419.log ;

3、然后重新创建一个 c:\log\log.log 文件保存2024年4月20当天的日志信息。

如果只设置了 file 而不设置 fileNamePattern 属性,则只会一直将日志信息添加在 c:\log\log.log 文件中。