I need to save the javax.net.debug=all output that is created to a file. I'm using log4j and I tried creating a logging proxy as in the code example below; however, it is not picking up the info. I am not sure where the javax.net.debug is being printed to. I tried capturing system.out and system.err this way but neither worked. Thanks for your help.
public class StdOutErrLog {
private static final Logger logger = Logger.getLogger(StdOutErrLog.class);
public static void tieSystemOutAndErrToLog() {
System.setOut(createLoggingProxy(System.out));
System.setErr(createLoggingProxy(System.err));
}
public static PrintStream createLoggingProxy(final PrintStream realPrintStream) {
return new PrintStream(realPrintStream) {
public void print(final String string) {
realPrintStream.print(string);
logger.info(string);
}
};
}
}
This is a long shot, but it's possible that overriding
print(String)
is not enough. For example, there is alsoprint(Object)
, etc., not to mention the variousappend()
andformat()
methods.Maybe the subsystem makes its copy of the values and you are too late when switching. Try doing this first in your main.
EDIT
OK - i missed completely your idiom. I think you should not use this inner class. You should define a PrintStream instance on an OutputStream that creates a new log entry upon every "\n". The way you do it now misses a lot of possibilities to "print around" your instance.
and then do
You maybe still want to include a reference to the previous stream - left as excercise :-)
You need to have log4j.properties file in class-path (/WEB-INF/classes/) with following content:
log4j.properties file
This will write your log entries into tomcat home directory /logs/custom.log
Hope this will help you.