logback中用日期/时间作为文件夹/目录/文件名

[size=small]logback中用日期/时间作为文件夹/目录/文件名

[url]http://stackoverflow.com/questions/16278720/logback-create-log-files-inside-folder-having-name-as-current-date[/url]

As mentioned in the documentation for fileNamePattern, you can specify multiple %d tokens so as put the date in the folder name of the archive filename:[/size]

<fileNamePattern>${PROJECT_HOME}\\projectname\\audits\\%d{yyyy-MM, aux}\\myproject_%d{yyyy-MM-dd}.%i.zip</fileNamePattern>


[size=small]Note that only one %d token can be primary, all other tokens must be marked as auxiliary by passing the 'aux' parameter.

But if you also want to put it in the file name of the non-arhcive filename, then you have two options:

1. use a <timestamp /> element to set a variable which you use in the path. But this timestamp will only be set once at startup, so it's good for batch runs but not for services.

2. Do like (1) above, but wrap the <appender/> and the <timestamp /> with a SiftingAppender, which will enable the timestamp to be re-evaluated, if using version of logback >=1.0.12. Not sure exactly how you'd want to configure the SiftingAppender. But hopefully that will put you on the right track.[/size]
### 解决 Java NoClassDefFoundError ch.qos.logback.core.spi.LifeCycle 错误 当遇到 `NoClassDefFoundError` 错误,特别是针对 `ch.qos.logback.core.spi.LifeCycle` 类时,通常意味着运行环境未能找到所需的 Logback 库。这可能是由于依赖项未正确下载或配置不当引起的。 #### 1. 检查 Maven 仓库中的 Logback 文件完整性 如果因网络问题导致 maven 自动下载不完全,则需要清理本地缓存并重新构建项目。建议删除 `.m2/repository/ch/qos/logback/` 下的相关目录,并更新项目的 pom.xml 后再次执行 mvn clean install 命令来强制刷新所有依赖关系[^2]。 ```bash rm -rf ~/.m2/repository/ch/qos/logback/ mvn clean install ``` #### 2. 验证 POM 中是否存在必要的 Logback 依赖 确保 Spring Boot 或其他应用程序的 POM 文件中包含了正确的 logback-core 和 logback-classic 的版本声明: ```xml <dependencies> <!-- Other dependencies --> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> <version>${logback.version}</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>${logback.version}</version> </dependency> </dependencies> ``` 这里 `${logback.version}` 是指具体的 Logback 版本号,在实际应用中应替换为合适的数值,比如 "1.2.3"[^3]。 #### 3. 确认 Classpath 路径设置无误 Logback 默认会按照特定顺序查找 classpath 下面的日志配置文件 (即依次尝试加载 `classpath:` 下的 `logback.groovy`, `logback-test.xml`, `logback.xml`) 。因此要确认这些资源确实存在于预期位置并且可以被 JVM 正确识别到[^1]。 通过以上措施应该能够有效解决由缺少 `LifeCycle` 接口所引发的 `NoClassDefFoundError` 异常情况。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值