You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Michael Erskine <mi...@ketech.com> on 2009/01/07 11:11:22 UTC
RE: I need to make logging in a complete application
> From: Ariel [mailto:isaacrc82@gmail.com]
> Subject: I need to make logging in a complete application
> I am newbie with log4j, I have made a distributed and multithreaded
> application where all the logging is made displaying de mesagges in the
> console using System.out.println. Now I want to redirect those messages
> to a
> file to have a trace of all the messages. Is there anyway to telling
> log4j
> that all the System.out messages write them into a file ???
Sure, redirect standard output to PrintStream subclass that does the logging for you: this should get you started...
// Redirect output
PrintStream ps = new PrintStream(new StdoutStderrStream(
new ByteArrayOutputStream()));
savedStdout = System.out;
savedStderr = System.err;
System.setOut(ps);
System.setErr(ps);
private class StdoutStderrStream extends FilterOutputStream {
public StdoutStderrStream(OutputStream s) {
super(s);
}
public void write(byte b[]) throws IOException {
// log here in threadsafe manner
}
public void write(byte b[], int off, int len) throws IOException {
// log here in threadsafe manner
}
}
Enjoy!
Michael Erskine.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org