We have a simple Webapp running on two Tomcat instances behind Apache (a Tomcat HA setup using mod_proxy_balancer
and mod_proxy_ajp
). The role of the webapp is to write incoming request data to a log file.
Given that each tomcat instance is running in it's own JVM, how should we implement the log file writing?
It would be excellent if both instances could write to the same file, but it would seem Log4J does not support that. We are open to writing our own file writer, but I am unsure if a java.nio.channels.FileLock
will do what we want.
Underneath is Debian with an ext3 file system, so if we were doing this in C or even PHP, we would use file system locks. However Java was written to abstract away the underlying system, and has grown to be a mess of classes in multiple packages all claiming to be able to write files in one way or another. Does anyone have any advice? Are there any packages out there that could help us?
Is it just a dumb dream to want to write to the same file from 2 JVMs in the first place? Surely I'm not the first.
Another requirement is for these files to be rolled every hour, but that is not as much of an issue (except maybe at file creation time).
Thanks!