I'm not saying what I want to do clearly enough, let's see... I am writing a JDBC driver. The JDBC Spec has a DataSource.setLogWriter(PrintStream) API drivers should implement.
Users can drop our driver into any tool that talks JDBC or write their own apps. In am concerned about the 'drop the driver anywhere' scenario, like in an Eclipse based tool; that may or may not use Eclipse DTP. Or anything else. The setLogWriter API can be called at any time, after Log4j has initialized itself for example. I do all my driver logging through Log4j. If a tool calls setLogWriter, I'd like the given PrintStream to become an Appender such that Log4j output appears there. The only way I see to do that is through pseudo-code like "getLoggerContext().getConfiguration().addAppender(PrintStreamAppender.createPrintStreamAppender(aPrintStream))" Gary On Fri, Jun 19, 2015 at 7:48 AM, Ralph Goers <[email protected]> wrote: > Sorry, I misunderstood the question. > > I’d look for a way to call the setLogWriter API during log4j configuration. > > Ralph > > On Jun 18, 2015, at 6:35 PM, Gary Gregory <[email protected]> wrote: > > I do not understand "Just have the initial writer be a noop." > > Gary > > On Thu, Jun 18, 2015 at 5:40 PM, Ralph Goers <[email protected]> > wrote: > >> Why reconfigure? Just have the initial writer be a noop. >> >> Sent from my iPhone >> >> On Jun 18, 2015, at 3:49 PM, Gary Gregory <[email protected]> wrote: >> >> Hi All: >> >> I have a use case where I use Log4j 2 for logging within a JDBC driver. >> I'd like to support the DataSource#setLogWriter(PrintStream) API in a >> fairly simple way. Granting that Log4j must be configured, if the user >> calls setLogWriter, I'd like to add a "print writer appender" to Log4j such >> that the user's PrintWriter becomes an appender target for log events. >> >> Any thoughts on getting this to work considering that the setLogWriter >> API can be called at any time in an apps life cycle. If I can get a clean >> impl, I'd like to put it in the iostreams module. >> >> Does this require a full reconfigure of log4j or is there a way to "just >> add an appender" programatically? >> >> Gary >> >> -- >> E-Mail: [email protected] | [email protected] >> Java Persistence with Hibernate, Second Edition >> <http://www.manning.com/bauer3/> >> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/> >> Spring Batch in Action <http://www.manning.com/templier/> >> Blog: http://garygregory.wordpress.com >> Home: http://garygregory.com/ >> Tweet! http://twitter.com/GaryGregory >> >> > > > -- > E-Mail: [email protected] | [email protected] > Java Persistence with Hibernate, Second Edition > <http://www.manning.com/bauer3/> > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/> > Spring Batch in Action <http://www.manning.com/templier/> > Blog: http://garygregory.wordpress.com > Home: http://garygregory.com/ > Tweet! http://twitter.com/GaryGregory > > > -- E-Mail: [email protected] | [email protected] Java Persistence with Hibernate, Second Edition <http://www.manning.com/bauer3/> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/> Spring Batch in Action <http://www.manning.com/templier/> Blog: http://garygregory.wordpress.com Home: http://garygregory.com/ Tweet! http://twitter.com/GaryGregory
