Log4j doesn't allow to catch stdout and stderr messages out of the box. However, you can still intercept them with a custom output stream, which is especially useful when you have to log data that third-party libraries write to the standard streams.
This has already been done by Jim Moore (have a look at the LoggingOutputStream
in the log4j source code). The issue is that this LoggingOutputStream
requires org.apache.log4j.Category
and org.apache.log4j.Priority
which are now partially deprecated.
If you ever wrote production multi-threaded server in Java you know how it is difficult to implement load balancing between worker threads. You need to fight many issues to have good load balancer:
ZeroMQ might tremendously help you with solving all these problems and much more. ZeroMQ is a high-performance asynchronous messaging library. It is native, but it has bindings for many languages and to be fair it is worth the hassle of dealing with native code.