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]
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值