Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dynamically creating & destroying logging appenders

Tags:

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 output to {thread-id}-10:00.log; and another thread of execution may begin an execution at 10:01, and its output would go to {thread-id}-10:01.log. I understand that this is not elegant.

My questions are:

  • is this possible?
  • does someone have an idea of how to approach?
  • is it possible to release/destroy an appender when it's no longer needed?

Thanks!

like image 704
Edward Q. Bridges Avatar asked Aug 06 '09 14:08

Edward Q. Bridges


1 Answers

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 ?

like image 92
Brian Agnew Avatar answered Oct 03 '22 06:10

Brian Agnew