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

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 15:54   1607   0
[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 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP