page banner
avatar
'How to intercept and log stdout and stderr messages with log4j' post illustration
How to intercept and log stdout and stderr messages with log4j

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.