dynamically creating & destroying logging appenders

前端 未结 2 417
猫巷女王i
猫巷女王i 2021-01-19 04:20

I have a legacy PSVM application which I\'d like to redirect its logging output to unique files per execution. So, if I invoke it at 10:00, then have it redirect it\'s outp

2条回答
  •  独厮守ぢ
    2021-01-19 04:59

    I would start with FileAppender and derive from that to create your own. Simply modify your version to get the current thread id and append a suitable thread-id/timestamp to the file prior to creation. You would maintain (say) a map of (buffered) FileWriters keyed on thread id.

    Writing appenders is quite trivial - here's a Javaworld guide on how to do it.

    In the above, is it at all likely that your program will start up twice in one minute ? Would you want to append a process id or similar to maintain uniqueness ?

提交回复
热议问题