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 Kenji Nakamura <ke...@cygent.com> on 2002/04/18 00:45:22 UTC
redirect Writer output to log4j?
Hello,
I'm writing an application utilizing WebGain's TOPLink, which is an object-relational mapping tool. The library has an API to dump log message and it is done by passing a java.io.Writer object into the method.
It looks like this;
session.setLog(new PrintWriter(System.out));
session.logMessage(); // turn on logging mode
...
(Activities dump log to System.out continuously)
I'd like to redirect TOPLink's messages to log4j. Is there a way to obtain a Writer object from log4j? I think writing an appender is not solution because I want to put in the info into log4j and take advantage of log4j's nice features such as delivering multiple appenders.
Thanks in advance,
----
Kenji Nakamura
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: redirect Writer output to log4j?
Posted by Kevin Steppe <ks...@pacbell.net>.
I'd make an extension to PrintWriter that sends things to log4j. Something like:
class Log4jWriter extends PrintWriter
{
Logger log = Logger.getLogger("Log4jWriter for TOPLink");
public void println(String message)
{
log.debug(message);
}
}
Then:
session.setLog(new Log4jWriter());
...
Of course you'll need to deal with a few more methods and some edge cases, but that should give you an idea.
Kevin
Kenji Nakamura wrote:
> Hello,
>
> I'm writing an application utilizing WebGain's TOPLink, which is an object-relational mapping tool. The library has an API to dump log message and it is done by passing a java.io.Writer object into the method.
>
> It looks like this;
> session.setLog(new PrintWriter(System.out));
> session.logMessage(); // turn on logging mode
> ...
> (Activities dump log to System.out continuously)
>
> I'd like to redirect TOPLink's messages to log4j. Is there a way to obtain a Writer object from log4j? I think writing an appender is not solution because I want to put in the info into log4j and take advantage of log4j's nice features such as delivering multiple appenders.
>
> Thanks in advance,
>
> ----
> Kenji Nakamura
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>